Esempio n. 1
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.ItemsPack.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
        {
            MoveState.TryWalkTo(Unit, TargetX, TargetY);
            return(true);
        }
    }
Esempio n. 2
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.
            MoveState.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y, TargetUnit.Width, TargetUnit.Height, Unit.Interaction.GetAttackRange());
        }

        return(true);
    }
Esempio n. 3
0
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        if (TargetUnit == Unit || !TargetUnit.IsAlive || !MapLogic.Instance.Objects.Contains(TargetUnit))
        {
            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("ATTACKING");
            int damage = UnityEngine.Random.Range(Unit.Stats.DamageMin, Unit.Stats.DamageMax);
            Unit.AddActions(new AttackAction(Unit, TargetUnit, DamageFlags.Raw, damage));
        }
        else
        {
            // make one step to the target.
            MoveState.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y);
        }

        return(true);
    }
Esempio n. 4
0
    public bool Process()
    {
        if (Executed && Unit.Actions[Unit.Actions.Count - 1].GetType() != typeof(AttackAction))
        {
            return(false);
        }

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

        if (TargetUnit == Unit || (TargetUnit != null && (!TargetUnit.IsAlive || !MapLogic.Instance.Objects.Contains(TargetUnit))))
        {
            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!
            //
            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 (Unit.Stats.Mana >= Spell.Template.ManaCost)
            {
                Unit.AddActions(new AttackAction(Unit, TargetUnit, Spell, TargetX, TargetY));
                Unit.Stats.TrySetMana(Unit.Stats.Mana - Spell.Template.ManaCost);
                Unit.DoUpdateView = true;
                Unit.DoUpdateInfo = true;
            }
            else
            {
                return(false); // :( no mana
            }
            Executed = true;
        }
        else
        {
            // make one step to the target.
            if (TargetUnit != null)
            {
                MoveState.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y);
            }
            else
            {
                MoveState.TryWalkTo(Unit, TargetX, TargetY);
            }
        }

        return(true);
    }
Esempio n. 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)
            {
                MoveState.TryWalkTo(Unit, TargetUnit.X, TargetUnit.Y, TargetUnit.Width, TargetUnit.Height, Spell.GetDistance());
            }
            else
            {
                MoveState.TryWalkTo(Unit, TargetX, TargetY, 0, 0, Spell.GetDistance());
            }
        }

        return(true);
    }