# MercanRey2.js — sampleState() (satır 632) [← MercanRey2.js](index.md) · [← Master](../../wiki.md) ```javascript function sampleState(state, caster, target) { var hpRatio = target.getMaxHp() <= 0 ? 1 : target.getHp() / target.getMaxHp(); var targetPos = target.getPosition(); var casterPos = caster.getPosition(); var contacts = collectContacts(target, caster); var text = entityText(target); var lore = detectLore(text); state.samples += 1; state.hpRatio = hpRatio; state.distanceToObserver = Math.sqrt(distanceSq(targetPos, casterPos)); state.maxSpeed = Math.max(state.maxSpeed, getMotionSpeed(target)); if (lore.id !== "unknown") { state.loreId = lore.id; state.className = lore.className; state.group = lore.group; state.will = lore.will; state.playerData = lore.playerData; state.weakness = lore.weakness; state.basePlan = lore.plan; mergeUnique(state.enemies, lore.enemies); mergeUnique(state.access, lore.access); mergeUnique(state.tags, lore.tags); } addKeywordTags(text, state.tags); mergeUnique(state.itemWarnings, detectItemRules(text)); if (target.isSprinting()) state.sprintSamples += 1; if (target.isSneaking()) state.sneakSamples += 1; if (isFlying(target)) state.flyingSamples += 1; if (getGameMode(target) === 3) { state.gm3Samples += 1; pushUnique(state.tags, "gm3"); } if (hpRatio < 0.4) state.lowHpSamples += 1; for (var key in contacts) { if (Object.prototype.hasOwnProperty.call(contacts, key)) { state.contacts[key] = contacts[key]; } } return state; } ```