public override void Execute()
        {
            NWCreature self = (NWCreature)Self;

            bool ex = (self.CurrentField).Creatures.IndexOf(Enemy) >= 0;

            if (ex)
            {
                if (!CanMove)
                {
                    Brain.Attack(Enemy, true);
                }
                else
                {
                    int chn = RandomHelper.GetRandom(5); // 20% chance
                    if (chn == 0)
                    {
                        if (Risk == AttackRisk.Evade)
                        {
                            Brain.Attack(Enemy, true);
                        }
                    }
                    else
                    {
                        ExtPoint res = Brain.GetEvadePos(Enemy);
                        if (!res.IsEmpty)
                        {
                            Brain.StepTo(res.X, res.Y);
                        }
                    }
                }
            }

            IsComplete = (!ex || !self.IsAvailable(Enemy, true));
        }
示例#2
0
        private void PrepareDebtTake()
        {
            try {
                NWCreature self   = (NWCreature)fSelf;
                Building   shop   = self.FindHouse();
                NWCreature debtor = null;

                Player player = GlobalVars.nwrGame.Player;
                int    debt   = player.GetDebt(self.Name);
                if (debt > 0 && self.IsAvailable(player, true) && !player.InRect(shop.Area))
                {
                    debtor = player;
                }

                DebtTakeGoal dtGoal = (DebtTakeGoal)FindGoalByKind(GoalKind.gk_DebtTake);
                if (debtor != null)
                {
                    if (dtGoal == null)
                    {
                        dtGoal = ((DebtTakeGoal)CreateGoal(GoalKind.gk_DebtTake));
                    }
                    dtGoal.Debtor = debtor;
                }
                else
                {
                    if (dtGoal != null)
                    {
                        ReleaseGoal(dtGoal);
                    }
                }
            } catch (Exception ex) {
                Logger.Write("TraderBrain.prepareDebtTake(): " + ex.Message);
            }
        }
示例#3
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            try {
                NWCreature self = (NWCreature)fSelf;
                int        gk   = goal.Kind;

                switch (gk)
                {
                case GoalKind.gk_ShopReturn:
                    goal.Value = 0.23f;
                    break;

                case GoalKind.gk_DebtTake:
                {
                    DebtTakeGoal dtGoal = (DebtTakeGoal)goal;
                    if (self.IsAvailable(dtGoal.Debtor, true))
                    {
                        goal.Value = 1f;
                    }
                    else
                    {
                        goal.Value = 0.1f;
                    }
                }
                break;

                case GoalKind.gk_WareReturn:
                    Building house = (Building)self.FindHouse();
                    if (house.Area.Contains(self.PosX, self.PosY))
                    {
                        goal.Value = 0.9f;
                    }
                    else
                    {
                        goal.Value = 0.22f;
                    }
                    break;

                default:
                    base.EvaluateGoal(goal);
                    break;
                }
            } catch (Exception ex) {
                Logger.Write("TraderBrain.evaluateGoal(): " + ex.Message);
            }
        }
        public override void Execute()
        {
            NWCreature self  = (NWCreature)Self;
            NWCreature enemy = (NWCreature)Enemy;

            bool   ex   = ((NWField)self.CurrentMap).Creatures.IndexOf(enemy) >= 0;
            RaceID race = self.Entry.Race;
            bool   los  = (race == RaceID.crDefault || race == RaceID.crHuman);

            IsComplete = (!ex || enemy.State == CreatureState.csDead || !self.IsAvailable(enemy, los));
            if (!IsComplete)
            {
                if (!CanMove)
                {
                    Brain.Attack(enemy, true);
                }
                else
                {
                    Brain.Attack(enemy, Risk == AttackRisk.ar_Wary);
                }

                IsComplete = (enemy.State == CreatureState.csDead);
            }
        }