// 普通攻击
    private void PlayAttack()
    {
        if (Owner.TargetAttacking == null || Owner.TargetAttacking.IsDead)
        {
            Owner.Idle();
            return;
        }

        _hasAttack       = false;
        _hasAttackFinish = false;
        _startAttackTime = BattleTime.GetTime();

        if (Owner.Cfg.TurnToTarget > 0)
        {
            // 攻击时转向目标
            Owner.TurnToTarget(Owner.TargetAttacking.Position);
        }

        if (!string.IsNullOrEmpty(Owner.AtkAnimation))
        {
            Owner.PlayAnimation(Owner.AtkAnimation);
            // TODO:播放攻击特效
            Owner.CallFunction("OnAttackPreview");
        }
    }
 public override void OnTick()
 {
     if (!_hasAttack)
     {
         // 攻击前摇时间到,出现弹道
         if (BattleTime.GetTime() - _startAttackTime >= Owner.GetAtkHitpoint())
         {
             LaunchProjectile();
             _hasAttack = true;
         }
     }
     else
     {
         // 大于攻击间隔
         if (BattleTime.GetTime() - _startAttackTime >= Owner.GetAtkInterval())
         {
             PlayAttack();
         }
         else
         {
             if (!_hasAttackFinish)
             {
                 // 如果当前动作播放完毕,则播放待机动作
                 if (Owner.IsCurrentAnimationFinish())
                 {
                     _hasAttackFinish = true;
                     Owner.PlayAnimation(AnimationName.Idle);
                 }
             }
         }
     }
 }
Beispiel #3
0
    // 添加 buff 或者光环
    public void AddBuff(string buffName, int duration, Skill skill, bool isStack = false)
    {
        if (string.IsNullOrEmpty(buffName))
        {
            return;
        }

        // buff 不能叠加则返回
        if (!isStack)
        {
            foreach (var item in _buffList)
            {
                if (item.Name == buffName)
                {
                    return;
                }
            }
        }
        Buff buff = new Buff();

        buff.Name       = buffName;
        buff.Script     = buffName;
        buff.Owner      = this;
        buff.Skill      = skill;
        buff.CreateTime = BattleTime.GetTime();
        buff.Duration   = duration;
        buff.RemainTime = duration;
        _buffList.Add(buff);
        buff.OnCreate();
        // 更新玩家属性
        UpdateProperty();
    }
Beispiel #4
0
    // 开始播放技能
    public void Play()
    {
        _startTime = BattleTime.GetTime();
        _state     = State.PHASE_START;

        // 通知脚本
        CallFunction("OnSpellStart");
    }
Beispiel #5
0
    // 每帧思考
    private void OnThink()
    {
        if (_thinkInterval <= 0)
        {
            return;
        }

        if (BattleTime.GetTime() - _lastThinkTime >= _thinkInterval)
        {
            _lastThinkTime = BattleTime.GetTime();
            CallFunction("OnThink");
        }
    }
Beispiel #6
0
 // 搜索敌人,单位在移动的时候也会搜索新的攻击目标,直到开始攻击
 private void ScanTarget()
 {
     if (BattleTime.GetTime() - _lastScanTime > 1000)
     {
         _lastScanTime = BattleTime.GetTime();
         Actor target = Owner.ScanTarget();
         if (target != null)
         {
             // 新的目标或者新的路径 TODO 将来进行优化如果路径没有改变则不需要重新寻路
             _currentMoveToPos = target.Position;
             SearchPath();
         }
     }
 }
Beispiel #7
0
 static int GetTime(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         int o = BattleTime.GetTime();
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #8
0
    // 处理每帧的回调
    private void ProcessThink()
    {
        if (_intervalTime <= 0)
        {
            return;
        }

        // 间隔触发的事件
        if (_intervalTime > 0 && BattleTime.GetTime() - _lastThinkTime >= _intervalTime)
        {
            // 通知脚本
            CallFunction("OnThink");
            _lastThinkTime = BattleTime.GetTime();
        }
    }
Beispiel #9
0
 private void ScanTarget()
 {
     if (BattleTime.GetTime() - _lastScanTime > 1000)
     {
         _lastScanTime = BattleTime.GetTime();
         Actor target = Owner.ScanTarget();
         if (target != null)
         {
             if (Owner.IsBuilding())
             {
                 Owner.PlayAttack(target);
             }
             else
             {
                 Owner.MoveToTarget(target);
             }
         }
     }
 }
Beispiel #10
0
    // 每逻辑帧更新
    public void OnTick()
    {
        if (BattleTime.GetTime() - _startTime > Duration)
        {
            // 技能结束
            _state = State.NOT_START;

            OnDestory();

            // 通知上层逻辑技能结束
            if (OnSkillFinish != null)
            {
                OnSkillFinish(this);
            }

            return;
        }

        ProcessThink();
    }
Beispiel #11
0
 // 逻辑帧更新(100ms)
 public override void OnTick()
 {
     if (!_applyHurt)
     {
         // 攻击前摇
         if (BattleTime.GetTime() - _startAttackTime >= Owner.GetAtkHitpoint())
         {
             _applyHurt = true;
             if (Owner.TargetAttacking != null)
             {
                 // 前摇结束,造成伤害
                 Owner.TargetAttacking.OnHit(Owner.GetDamage());
                 // TODO:这里仅迁就王子冲锋首次攻击会有伤害加成,以后需要修改更加通用框架
                 Owner.CallFunction("OnAfterAttack");
             }
         }
     }
     else
     {
         if (BattleTime.GetTime() - _startAttackTime >= Owner.GetAtkInterval())
         {
             PlayAttack();
         }
         //下一轮攻击时间未到
         else
         {
             //if (!_hasAttackFinish)
             //{
             //    // 如果当前动作播放完毕,则播放待机动作
             //    if (Owner.IsCurrentAnimationFinish())
             //    {
             //        _hasAttackFinish = true;
             //        Owner.PlayAnimation(AnimationName.Idle);
             //    }
             //}
         }
     }
 }