示例#1
0
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        if (Unit.X == WalkX && Unit.Y == WalkY)
        {
            return(false);
        }

        if (MapLogic.Instance.LevelTime - LastGoodPath > 5 * MapLogic.TICRATE && LastBadPath > LastGoodPath)
        {
            return(false); // if last good path was found more time ago, and last path was bad... break out, but wait for 5 seconds
        }
        if (!Walker.TryWalkTo(Unit, WalkX, WalkY, 0, 0))
        {
            LastBadPath = MapLogic.Instance.LevelTime;
            return(true);
        }
        else
        {
            LastGoodPath = MapLogic.Instance.LevelTime;
        }

        return(true);
    }
示例#2
0
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        // check if sack still exists
        MapSack targetsack = MapLogic.Instance.GetSackAt(TargetX, TargetY);

        if (targetsack == null)
        {
            return(false);
        }

        // if unit is on target cell, just pick up
        if (Unit.X <= TargetX && Unit.Y <= TargetY &&
            Unit.X + Unit.Width > TargetX && Unit.Y + Unit.Height > TargetY)
        {
            // pick the target sack up.
            // add money
            for (int i = 0; i < targetsack.Pack.Count; i++)
            {
                Item newItem = Unit.ItemsPack.PutItem(Unit.ItemsPack.Count, new Item(targetsack.Pack[i], targetsack.Pack[i].Count));
                // display "you have picked up ..."
                Server.NotifyItemPickup(Unit, targetsack.Pack[i].Class.ItemID, newItem.Count);
            }

            if (targetsack.Pack.Money > 0)
            {
                Unit.Player.Money += targetsack.Pack.Money;
                Server.NotifyItemPickup(Unit, -1, targetsack.Pack.Money);
            }

            MapLogic.Instance.RemoveSackAt(TargetX, TargetY);

            if (NetworkManager.IsServer)
            {
                Server.NotifyUnitPack(Unit);
            }

            return(false); // done
        }
        else
        {
            Walker.TryWalkTo(Unit, TargetX, TargetY, 0, 0);
            return(true);
        }
    }
示例#3
0
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        if (TargetUnit == Unit || !TargetUnit.IsAlive || !TargetUnit.IsLinked)
        {
            return(false);
        }

        if (!Unit.Interaction.CheckCanAttack(TargetUnit))
        {
            return(false);
        }

        // assume melee attack right now
        // check if in direct proximity
        if (Unit.Interaction.GetClosestDistanceTo(TargetUnit) <= Unit.Interaction.GetAttackRange() + 0.5f)
        {
            // in direct proximity!
            //
            Vector2i enemyCell   = TargetUnit.Interaction.GetClosestPointTo(Unit);
            int      angleNeeded = Unit.FaceCellPrecise(enemyCell.x, enemyCell.y);
            if (Unit.Angle != angleNeeded)
            {
                Unit.AddActions(new RotateAction(Unit, angleNeeded));
                return(true);
            }

            //
            //Debug.LogFormat("ID {0} ATTACKING", Unit.ID);
            int         damage = Random.Range(Unit.Stats.DamageMin, Unit.Stats.DamageMax);
            DamageFlags df     = Unit.GetDamageType();
            // we need to compare Option to set damage flags properly here
            Unit.AddActions(new AttackAction(Unit, TargetUnit, df, damage));
        }
        else
        {
            //Debug.LogFormat("ID {0} TRY WALK TO", Unit.ID);
            // make one step to the target.
            Walker.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y, TargetUnit.Width, TargetUnit.Height, Unit.Interaction.GetAttackRange());
        }

        return(true);
    }
示例#4
0
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        if (Structure == null || Structure.Class == null || !Structure.Class.Usable)
        {
            return(false);
        }

        if (!(Unit is MapHuman mh) || !mh.IsHero)
        {
            return(false);
        }

        // check if close enough
        int x = Structure.X - 1;
        int y = Structure.Y - 1;
        int w = Structure.Width + 2;
        int h = Structure.Height + 2;

        // done walking
        if (new Rect(x, y, w, h).Overlaps(new Rect(Unit.X, Unit.Y, Unit.Width, Unit.Height)))
        {
            // we are the server.
            // initiate building view...
            if (Unit.CurrentStructure != null)
            {
                Unit.CurrentStructure.HandleUnitLeave(Unit);
            }
            Structure.HandleUnitEnter(Unit);
            return(false);
        }

        //Debug.LogFormat("ID {0} TRY WALK TO", Unit.ID);
        // make one step to the target.
        Walker.TryWalkTo(Unit, Structure.X, Structure.Y, Structure.Width, Structure.Height);
        return(true);
    }
示例#5
0
    public bool Process()
    {
        // check target. if target is outside map range, terminate. server doesn't really handle this well
        if (TargetX < 8 || TargetY < 8 || TargetX >= MapLogic.Instance.Width - 8 || TargetY >= MapLogic.Instance.Height - 8)
        {
            if (TargetUnit != null)
            {
                TargetX = -1;
                TargetY = -1;
            }
            else
            {
                return(false);
            }
        }

        if (Executed && Unit.Actions[Unit.Actions.Count - 1].GetType() != typeof(AttackAction))
        {
            return(false);
        }

        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        if ((IsAttack && TargetUnit == Unit) || (TargetUnit != null && (!TargetUnit.IsAlive || !TargetUnit.IsLinked)))
        {
            return(false);
        }

        if (TargetUnit != null && !Unit.Interaction.CheckCanAttack(TargetUnit))
        {
            return(false);
        }

        // assume melee attack right now
        // check if in direct proximity
        if ((TargetUnit != null && Unit.Interaction.GetClosestDistanceTo(TargetUnit) <= Spell.GetDistance() + 0.5f) ||
            (TargetUnit == null && (Unit.Interaction.GetClosestPointTo(TargetX, TargetY) - new Vector2i(TargetX, TargetY)).magnitude <= Spell.GetDistance() + 0.5f))
        {
            // in direct proximity!
            //
            if (TargetUnit != Unit)
            {
                Vector2i enemyCell   = (TargetUnit != null ? TargetUnit.Interaction.GetClosestPointTo(Unit) : new Vector2i(TargetX, TargetY));
                int      angleNeeded = Unit.FaceCellPrecise(enemyCell.x, enemyCell.y);
                if (Unit.Angle != angleNeeded)
                {
                    Unit.AddActions(new RotateAction(Unit, angleNeeded));
                    return(true);
                }
            }

            //
            //Debug.LogFormat("ATTACKING");
            if ((Spell.Item != null || Unit.Stats.Mana >= Spell.Template.ManaCost) &&
                (!Spell.ItemDisposable || Unit.ItemsPack.Contains(Spell.Item)))
            {
                Unit.AddActions(new AttackAction(Unit, TargetUnit, Spell, TargetX, TargetY));
                if (Spell.Item == null && Unit.Stats.TrySetMana(Unit.Stats.Mana - Spell.Template.ManaCost) && NetworkManager.IsServer)
                {
                    Server.NotifyUnitStatsShort(Unit);
                }
                else if (Spell.Item != null && Spell.ItemDisposable && Unit.ItemsPack.TakeItem(Spell.Item, 1) != null)
                {
                    Server.NotifyUnitPack(Unit);
                }
                Unit.DoUpdateView = true;
                Unit.DoUpdateInfo = true;
            }
            else
            {
                return(false); // :( no mana
            }
            Executed = true;
        }
        else
        {
            // make one step to the target.
            if (TargetUnit != null)
            {
                Walker.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y, TargetUnit.Width, TargetUnit.Height, Spell.GetDistance());
            }
            else
            {
                Walker.TryWalkTo(Unit, TargetX, TargetY, 0, 0, Spell.GetDistance());
            }
        }

        return(true);
    }