public FDCreature GetPreferredAttackTargetInRange(int creatureId) { FDCreature creature = this.GetCreature(creatureId); AttackItemDefinition attackItem = creature.Data.GetAttackItem(); if (attackItem == null) { return(null); } FDSpan span = attackItem.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(this.gameField, creature.Position, span.Max, span.Min); FDRange range = finder.CalculateRange(); // Get a preferred target in range foreach (FDPosition position in range.Positions) { FDCreature target = this.GetCreatureAt(position); if (target != null && target.Faction == CreatureFaction.Enemy) { return(target); } } return(null); }
public override void TakeAction() { if (this.NeedAndCanRecover()) { this.GameAction.DoCreatureRest(this.Creature.CreatureId); return; } // Get target FDCreature target = this.LookForAggressiveTarget(); // According to the target, find the nearest position within the Move scope, and get the path to that position FDMovePath movePath = this.DecidePositionAndPath(target.Position); // Do the walk this.GameAction.CreatureWalk(new SingleWalkAction(this.Creature.CreatureId, movePath)); FDPosition destination = movePath.Desitination ?? this.Creature.Position; AttackItemDefinition item = this.Creature.Data.GetAttackItem(); if (item != null) { FDSpan span = item.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(this.GameAction.GetField(), destination, span.Max, span.Min); FDRange range = finder.CalculateRange(); if (range.Contains(target.Position)) { // If in attack range, attack the target this.GameAction.DoCreatureAttack(this.Creature.CreatureId, target.Position); } } this.GameAction.DoCreatureRest(this.Creature.CreatureId); }
public static int CalculateDp(CreatureData creatureData) { int delta = 0; AttackItemDefinition attackItem = creatureData.GetAttackItem(); if (attackItem != null) { delta = attackItem.Dp; } DefendItemDefinition defendItem = creatureData.GetDefendItem(); if (defendItem != null) { delta = defendItem.Dp; } int total = creatureData.Dp + delta; if (creatureData.Effects.Contains(CreatureData.CreatureEffects.EnhancedDp)) { total = (int)(total * 1.15f); } return(total); }
protected string GetItemDescription(ItemDefinition item) { if (item == null) { return(null); } string description = string.Empty; if (item is AttackItemDefinition) { AttackItemDefinition attackItem = item as AttackItemDefinition; description = string.Format(@"+AP {0}", StringUtils.Digit2(attackItem.Ap)); if (attackItem.Dp > 0) { description += string.Format(@" +DP {0}", StringUtils.Digit2(attackItem.Dp)); } if (attackItem.Dp < 0) { description += string.Format(@" -DP {0}", StringUtils.Digit2(-attackItem.Dp)); } return(description); } if (item is DefendItemDefinition) { DefendItemDefinition defendItem = item as DefendItemDefinition; description = string.Format(@"+DP {0}", StringUtils.Digit2(defendItem.Dp)); return(description); } if (item is ConsumableItemDefinition) { ConsumableItemDefinition consumableItem = item as ConsumableItemDefinition; string prefix = string.Empty; switch (consumableItem.UseType) { case ItemUseType.Hp: prefix = "HP"; break; case ItemUseType.Mp: prefix = "MP"; break; case ItemUseType.HpMax: prefix = "HP"; break; case ItemUseType.MpMax: prefix = "MP"; break; case ItemUseType.Dx: prefix = "DX"; break; case ItemUseType.Mv: prefix = "MV"; break; default: break; } description = string.Format(@"+{0} {1}", prefix, consumableItem.Quantity); return(description); } return(string.Empty); }
private void LoadItemDefinitions() { itemDefinitions = new Dictionary <int, ItemDefinition>(); ResourceDataFile fileReader = new ResourceDataFile(@"Data/Item"); int usableItemCount = fileReader.ReadInt(); for (int i = 0; i < usableItemCount; i++) { ConsumableItemDefinition def = ConsumableItemDefinition.ReadFromFile(fileReader); itemDefinitions[def.ItemId] = def; } int attackItemCount = fileReader.ReadInt(); for (int i = 0; i < attackItemCount; i++) { AttackItemDefinition def = AttackItemDefinition.ReadFromFile(fileReader); itemDefinitions[def.ItemId] = def; } int defendItemCount = fileReader.ReadInt(); for (int i = 0; i < defendItemCount; i++) { DefendItemDefinition def = DefendItemDefinition.ReadFromFile(fileReader); itemDefinitions[def.ItemId] = def; } int specialItemCount = fileReader.ReadInt(); for (int i = 0; i < specialItemCount; i++) { SpecialItemDefinition def = SpecialItemDefinition.ReadFromFile(fileReader); itemDefinitions[def.ItemId] = def; } int moneyItemCount = fileReader.ReadInt(); for (int i = 0; i < moneyItemCount; i++) { MoneyItemDefinition def = MoneyItemDefinition.ReadFromFile(fileReader); itemDefinitions[def.ItemId] = def; } }
private static AttackInformation AttackFrom(FDCreature subject, FDCreature target, GameField field) { bool isHit = FDRandom.BoolFromRate(subject.Data.CalculatedHit - target.Data.CalculatedEv); bool isCritical = FDRandom.BoolFromRate(commonCriticalAttackRate); int reduceHp = 0; if (isHit) { FDPosition pos = subject.Position; ShapeDefinition shape = field.GetShapeAt(pos.X, pos.Y); int adjustedAp = subject.Data.CalculatedAp * (100 + shape.AdjustedAp) / 100; FDPosition targetPos = target.Position; ShapeDefinition targetShape = field.GetShapeAt(targetPos.X, targetPos.Y); int adjustedDp = target.Data.CalculatedDp * (100 + shape.AdjustedDp) / 100; int attackMax = adjustedAp - adjustedDp; int attackMin = (int)(attackMax * 0.9f); reduceHp = FDRandom.IntFromSpan(attackMin, attackMax); reduceHp = (reduceHp < 0) ? 0 : reduceHp; if (isCritical) { reduceHp *= 2; } // Poisoned AttackItemDefinition attackItem = subject.Data.GetAttackItem(); if (attackItem != null) { bool isPoisoned = FDRandom.BoolFromRate(attackItem.GetPoisonRate()); if (isPoisoned) { target.Data.SetEffect(CreatureData.CreatureEffects.Poisoned); } } } AttackInformation info = new AttackInformation(target.Data.Hp, target.Data.Hp - reduceHp, isCritical); target.Data.UpdateHp(-reduceHp); return(info); }
public static int CalculateEv(CreatureData creatureData) { int delta = 0; AttackItemDefinition attackItem = creatureData.GetAttackItem(); if (attackItem != null) { delta = attackItem.Ev; } DefendItemDefinition defendItem = creatureData.GetDefendItem(); if (defendItem != null) { delta = defendItem.Ev; } return(creatureData.Dx + delta); }
public override void OnEnter() { base.OnEnter(); if (this.AttackRange == null) { AttackItemDefinition attackItem = this.Creature.Data.GetAttackItem(); if (attackItem == null) { return; } FDSpan span = attackItem.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(gameAction.GetField(), this.Creature.Position, span.Max, span.Min); this.AttackRange = finder.CalculateRange(); } // Display the attack range on the UI. ShowRangePack pack = new ShowRangePack(this.AttackRange); SendPack(pack); }
public static int CalculateHit(CreatureData creatureData) { AttackItemDefinition attackItem = creatureData.GetAttackItem(); return(creatureData.Dx + attackItem.Hit); }