protected override void DoBehaviour(HashSet <GameObject> changedObjects)
        {
            //TODO: replace by closest player.
            Player player = GameWorld.Find(Player.LocalPlayerName) as Player;

            if (player.Tile.SeenBy.ContainsKey(this))
            {
                bool ableToHit = AttackEvent.AbleToHit(this, player.Tile, Reach);
                if (ableToHit)
                {
                    Attack(player);
                    changedObjects.Add(player);

                    int cost = BaseActionCost;
                    if ((EquipmentSlots.Find("bodySlot") as RestrictedItemSlot).SlotItem != null)
                    {
                        cost = (int)(cost * ((EquipmentSlots.Find("bodySlot") as RestrictedItemSlot).SlotItem as BodyEquipment).WalkCostMod);
                    }
                    actionPoints -= cost;
                }
                else
                {
                    GoTo(changedObjects, player);
                }
            }
            else
            {
                Idle();
            }
        }
Exemple #2
0
        /// <summary>
        /// Pathfind towards a given player
        /// </summary>
        /// <param name="player">The player to target with Pathfinding</param>
        public override void GoTo(HashSet <GameObject> changedObjects, Player player)
        {
            TileField tf = GameWorld.Find("TileField") as TileField;


            if (player.Tile.SeenBy.ContainsKey(this))
            {
                bool ableToHit = AttackEvent.AbleToHit(this, player.Tile, this.Reach);

                Special_AbleToHit(player);

                if (special_ableToHit && actionpoints_used >= actionpoints_cooldown)
                {
                    Special_Attack(player, mod);

                    actionpoints_used = 0;
                    actionPoints      = 0;
                    changedObjects.Add(player);
                }
                else if (ableToHit)
                {
                    Attack(player);

                    int cost = BaseActionCost;
                    if ((EquipmentSlots.Find("bodySlot") as ItemSlot).SlotItem != null)
                    {
                        cost = (int)(cost * ((EquipmentSlots.Find("bodySlot") as ItemSlot).SlotItem as BodyEquipment).WalkCostMod);
                    }
                    actionPoints -= cost;
                    changedObjects.Add(player);
                }
                else
                {
                    PathFinder  pf   = new PathFinder(tf);
                    List <Tile> path = pf.ShortestPath(Tile, player.Tile);
                    // TODO?:(assuming there are tiles that cannot be walked over but can be fired over)
                    // check if there is a path to a spot that can hit the player (move closer water to fire over it)
                    if (path.Count > 0)
                    {
                        changedObjects.Add(this);
                        changedObjects.Add(Tile);
                        changedObjects.Add(path[0]);

                        MoveTo(path[0]);
                        actionPoints -= BaseActionCost;
                    }
                    else
                    {
                        Idle();
                    }
                }
            }
            else
            {
                Idle();
            }
        }
Exemple #3
0
        public override void HandleInput(InputHelper inputHelper)
        {
            if (Health > 0 && animations["die"] != CurrentAnimation)
            {
                Action onClick = () =>
                {
                    Player      player = GameWorld.Find(Player.LocalPlayerName) as Player;
                    AttackEvent aE     = new AttackEvent(player, this);
                    Server.Send(aE);
                };

                inputHelper.IfMouseLeftButtonPressedOn(this, onClick);

                base.HandleInput(inputHelper);
            }
        }
Exemple #4
0
        public virtual bool SkillValidation(Living caster, Living livingTarget, Tile TileTarget)
        {
            if (caster.CurrentSkill != null)
            {
                bool manacost = caster.Mana >= ManaCost;
                bool AtH;

                if (livingTarget != null)
                {
                    AtH = AttackEvent.AbleToHit(caster, livingTarget.Tile, skillReach);
                }
                else if (TileTarget != null)
                {
                    AtH = AttackEvent.AbleToHit(caster, TileTarget, skillReach);
                }
                else
                {
                    throw new Exception("invalid target");
                }

                return(manacost && AtH);
            }
            return(false);
        }