public override void Attach(LogicUnit g, LogicUnit t)
        {
            base.Attach(g, t);

            int hurtValue = 0;

            if (calculateType == CalculateType.Percent)
            {
                hurtValue = MainValue * t.maxHp;

                t.Hurt(hurtValue, AttackPropertyType.MagicAttack, false, g);
            }
            else if (calculateType == CalculateType.NaturalNumber)
            {
                hurtValue = MainValue;

                t.Hurt(hurtValue, AttackPropertyType.MagicAttack, false, g);
            }
            else
            {
                DebugUtils.LogError(DebugUtils.Type.AI_AttributeEffect, string.Format("Can't handler this hurt type {0} in {1} {2} ", hurtValue, type, attributeAffectType));
            }

            DebugUtils.LogWarning(DebugUtils.Type.AI_AttributeEffect, string.Format("{0} {1} {2} has been hurt the unit value to {3}", metaId, type, attributeAffectType, hurtValue));

            Detach();
        }
Example #2
0
        public virtual void Fight()
        {
            if (target != null && target.Alive())
            {
                DebugUtils.Log(DebugUtils.Type.AI_Npc, "the " + npcType + " npc " + id + " begins to attack target " + target.id);

                damage = physicasAttack;
                target.Hurt(damage, hurtType, false, this);
            }
        }
        public override void Update(int deltaTime)
        {
            base.Update(deltaTime);

            LogicUnit target = owner.target;

            if (target != null && target.Alive())
            {
                long distance = FixVector3.SqrDistance(target.position, owner.position);
                if (distance < owner.attackRadius)
                {
                    if (inFightInterval)
                    {
                        fightIntervalTimer += deltaTime;

                        if (fightIntervalTimer >= fightInterval)
                        {
                            fightState         = FightState.StartSwingPoint;
                            fightIntervalTimer = 0;
                            inFightInterval    = false;
                        }
                    }
                    else
                    {
                        fightState          = GetCurrentState(fightDurationTimer);
                        fightDurationTimer += deltaTime;

                        if (fightState == FightState.StartSwingPoint)
                        {
                            owner.direction = target.position - owner.position;

                            RenderMessage rm = new RenderMessage();
                            rm.ownerId   = owner.id;
                            rm.direction = owner.direction.vector3;
                            rm.type      = RenderMessage.Type.SummonedUnitAttack;
                            owner.PostRenderMessage(rm);
                        }
                        else if (fightState == FightState.HitPoint)
                        {
                            owner.damage = Formula.GetAttackFloatingValue(owner.physicalAttack, owner.GetRandomNumber(), owner.GetRandomNumber(owner.physicalAttackVar));

                            List <LogicUnit> targets = owner.FindOpponent();

                            for (int i = 0; i < targets.Count; i++)
                            {
                                LogicUnit t = targets[i];

                                // Check target state and still in the attack range
                                if (t != null && t.Alive())
                                {
                                    t.Hurt(owner.damage, AttackPropertyType.PhysicalAttack, false, owner.ownerSoldier);
                                }
                            }
                        }
                        else if (fightState == FightState.FightEnd)
                        {
                            inFightInterval    = true;
                            fightDurationTimer = 0;
                        }
                    }
                }
                else
                {
                    owner.Idle();
                }
            }
            else
            {
                owner.Idle();
            }
        }