Exemplo n.º 1
0
 public TNode GetNode(BaseUnit unit)
 {
     if (unit == null)
     {
         return(null);
     }
     if (SeizeNodesUnit.ContainsKey(unit))
     {
         TNode node = SeizeNodesUnit[unit];
         return(node);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 public AudioSource PlayPlayerSFX(string clipName, BaseUnit player, Vector3?pos = null, bool isLoop = false, float maxDis = 60.0f)
 {
     if (clipName == null)
     {
         return(null);
     }
     if (player == null)
     {
         return(null);
     }
     if (!player.IsLocalPlayer())
     {
         return(null);
     }
     return(PlaySFX(clipName, pos, isLoop, maxDis));
 }
Exemplo n.º 3
0
        public ABPath Move(BaseUnit unit, Vector3 pos, float speed = 1.0f)
        {
            if (pos.IsInv())
            {
                return(null);
            }
            if (UnitMoveCoroutineHandle.IsRunning)
            {
                BattleCoroutine.Kill(UnitMoveCoroutineHandle);
                Callback_OnMoveEnd?.Invoke(PreMoveUnit);
            }
            var path = StartABPath(unit.Pos, pos, null);

            UnitMoveCoroutineHandle = BattleCoroutine.Run(MoveAlongPath(unit, path, speed));
            return(path);
        }
Exemplo n.º 4
0
        public TDBaseAlertData Add(string alertName, BaseUnit cast = null)
        {
            if (!Table.Contains(alertName))
            {
                if (CommonAlert == alertName)
                {
                    CLog.Error("请手动添加 CommonAlert");
                }
                return(null);
            }
            TDBaseAlertData tempAlert = null;

            if (IsHaveCache(alertName))
            {
                tempAlert = GetCache(alertName);
                CachesAlert.Remove(alertName);
            }
            else
            {
                tempAlert = Table.Find(alertName).Copy();
            }

            tempAlert.Cast = cast?cast:LocalPlayer;

            if (tempAlert == null)
            {
                CLog.Error("未找到alert errorId=" + alertName);
                return(null);
            }
            //判断通知是否可以被合并
            var mergeAlert = CanMerge(tempAlert);

            if (mergeAlert != null)
            {
                mergeAlert.OnMerge();
                Callback_OnMerge?.Invoke(mergeAlert);
            }
            else
            {
                tempAlert.ID = IDMgr.GetNextId();
                Data.Add(tempAlert);
                tempAlert.OnBeAdded(SelfBaseUnit);
                Callback_OnAdded?.Invoke(tempAlert);
                tempAlert.OnStart();
            }
            return(tempAlert);
        }
Exemplo n.º 5
0
        IEnumerator <float> MoveAlongPath(BaseUnit unit, ABPath path, float speed)
        {
            if (path.error || path.vectorPath.Count == 0)
            {
                throw new ArgumentException("Cannot follow an empty path");
            }

            PreMoveUnit = unit;
            Callback_OnMoveStart?.Invoke(unit);

            // Very simple movement, just interpolate using a catmull rom spline
            float distanceAlongSegment = 0;

            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                var p0 = path.vectorPath[Mathf.Max(i - 1, 0)];
                // Start of current segment
                var p1 = path.vectorPath[i];
                // End of current segment
                var p2 = path.vectorPath[i + 1];
                var p3 = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)];

                var segmentLength = Vector3.Distance(p1, p2);

                while (distanceAlongSegment < segmentLength)
                {
                    var interpolatedPoint = MathUtil.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);

                    var targetRot = Quaternion.LookRotation((p2 - p1).SetY(0), Vector3.up);
                    unit.Rot = Quaternion.Slerp(unit.Rot, targetRot, Time.deltaTime * 10);

                    unit.transform.position = interpolatedPoint;

                    Callback_OnMovingAlone?.Invoke(unit, p0, p1, p2, p3);
                    yield return(Timing.WaitForOneFrame);

                    distanceAlongSegment += Time.deltaTime * speed;
                }

                distanceAlongSegment -= segmentLength;
            }

            Vector3 target = path.vectorPath[path.vectorPath.Count - 1];

            unit.Pos = target;
            Callback_OnMoveEnd?.Invoke(unit);
        }
Exemplo n.º 6
0
        // 设置阻挡得Node,输入Null表示清空
        public void SetBlockNode(BaseUnit unit, List <TNode> nodes)
        {
            if (unit == null)
            {
                return;
            }
            HashList <TNode> preNodes = null;

            if (BlockNodesUnit.ContainsKey(unit))
            {
                preNodes = BlockNodesUnit[unit];
            }

            //先清除之前残余得数据
            if (preNodes != null)
            {
                foreach (var item in preNodes)
                {
                    AllBlockers.Remove(item);
                    if (BlockNodes.ContainsKey(item))
                    {
                        BlockNodes[item].Remove(unit);
                    }
                    if (BlockNodes[item].Count == 0)
                    {
                        BlockNodes.Remove(item);
                    }
                }
                BlockNodesUnit.Remove(unit);
            }


            if (nodes != null)
            {
                HashList <TNode> newHashSetNodes = new HashList <TNode>(nodes);
                foreach (var item in nodes)
                {
                    AllBlockers.Add(item);
                    if (!BlockNodes.ContainsKey(item))
                    {
                        BlockNodes.Add(item, new HashList <BaseUnit>());
                    }
                    BlockNodes[item].Add(unit);
                }
                BlockNodesUnit.Add(unit, newHashSetNodes);
            }
        }
Exemplo n.º 7
0
 public bool MoveToUnitQueue(BaseUnit unit)
 {
     if (unit == null)
     {
         return(false);
     }
     if (unit == SelfBaseUnit)
     {
         return(false);
     }
     if (unit.Pos.IsInv())
     {
         return(false);
     }
     AStarMgr.AddMoveQueue(SelfBaseUnit, unit);
     return(true);
 }
Exemplo n.º 8
0
 protected override void OnSetPlayerBase(BaseUnit oldPlayer, BaseUnit newPlayer)
 {
     base.OnSetPlayerBase(oldPlayer, newPlayer);
     if (AlertMgr != null)
     {
         AlertMgr.Callback_OnAdded          -= OnAlertAdded;
         AlertMgr.Callback_OnRemoved        -= OnAlertRemoved;
         AlertMgr.Callback_OnMerge          -= OnAlertMerge;
         AlertMgr.Callback_OnCommingTimeOut -= OnAlertCommingTimeOut;
     }
     AlertMgr = NewAlertMgr;
     AlertMgr.Callback_OnAdded          += OnAlertAdded;
     AlertMgr.Callback_OnRemoved        += OnAlertRemoved;
     AlertMgr.Callback_OnMerge          += OnAlertMerge;
     AlertMgr.Callback_OnCommingTimeOut += OnAlertCommingTimeOut;
     RecreateAlerts();
 }
Exemplo n.º 9
0
        public void Add(IBaseSenseMgr sense, BaseUnit unit)
        {
            if (!UnitsSense.ContainsKey(unit))
            {
                UnitsSense.Add(unit, new HashList <string>());
            }
            if (!TypedSenseUnits.ContainsKey(sense.SenseName))
            {
                TypedSenseUnits.Add(sense.SenseName, new HashList <BaseUnit>());
            }
            Units.Add(unit);
            UnitsSense[unit].Add(sense.SenseName);
            TypedSenseUnits[sense.SenseName].Add(unit);

            OnDetectionChange(unit);
            OnDetectionAdd(unit);
        }
Exemplo n.º 10
0
 public void AddMoveQueue(BaseUnit unit, BaseUnit target)
 {
     if (unit == null)
     {
         return;
     }
     if (target == null)
     {
         return;
     }
     if (MoveQueue.ContainsKey(unit))
     {
         MoveQueue[unit] = target;
         return;
     }
     MoveQueue.Add(unit, target);
 }
Exemplo n.º 11
0
        //移动范围是否可以链接到目标
        public bool IsCanConstantConnection(BaseUnit unit)
        {
            if (ConstantNodesMove == null || ConstantNodesMove.Count == 0)
            {
                return(false);
            }
            HashList <GraphNode> links = AStarMgr.GetConnectionsBlocker(unit);

            foreach (var item in links)
            {
                if (ConstantNodesMove.Contains(item))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 12
0
        public virtual List <TData> Add(string[] buffName, BaseUnit caster = null, float step = 0.0f, TDBaseSkillData skill = null)
        {
            if (buffName == null)
            {
                return(null);
            }
            if (buffName.Length == 0)
            {
                return(null);
            }
            List <TData> ret = new List <TData>();

            for (int i = 0; i < buffName.Length; ++i)
            {
                ret.Add(Add(buffName[i], caster, step, skill));
            }
            return(ret);
        }
Exemplo n.º 13
0
        public static void SelectUnit(BaseUnit unit)
        {
            if (IsBlockSelectUnit)
            {
                return;
            }
            //选择一个单位后无法再次选择
            if (IsInSelectUnitTime())
            {
                return;
            }
            if (unit)
            {
                //检测这个是否可以被选择
                if (!Ins.IsCanSelectUnit(unit))
                {
                    return;
                }
            }

            //检测是否重复选择
            bool isRepeat = false;

            if (SelectedUnit == unit)
            {
                isRepeat = true;
            }
            else
            {
                SelectedUnit?.OnUnBeSelected();
            }

            if (unit)
            {
                unit?.OnBeSelected(isRepeat);
                SelectedUnit = unit;
            }
            else
            {
                SelectedUnit = null;
            }
            SelectUnitTimer.Restart();
            Ins?.OnSelectedUnit(SelectedUnit, isRepeat);
        }
Exemplo n.º 14
0
        // 移动到指定单位
        public bool MoveIntoUnit(BaseUnit unit)
        {
            if (unit == null)
            {
                return(false);
            }
            if (unit.Pos.IsInv())
            {
                return(false);
            }
            MoveTargetUnit   = unit;
            IsCanUnitOverlap = true;
            MoveType         = BasicMoveType2D.MoveIntoUnit;
            var targetNode = AStarMgr.GetNode(unit.Pos);
            var ret        = _moveIntoNode(targetNode);

            IsTriggerDoTraversal = true;
            return(ret);
        }
Exemplo n.º 15
0
 public void ClearSeizeNode(TNode node, BaseUnit unit)
 {
     if (node == null)
     {
         return;
     }
     if (unit == null)
     {
         return;
     }
     //添加新的SeizeNode
     if (!SeizeNodes.ContainsKey(node))
     {
         SeizeNodes.Add(node, new HashSet <BaseUnit>());
     }
     SeizeNodes[node].Remove(unit);
     //设置SeizeNodesUnit
     SeizeNodesUnit.Remove(unit);
 }
Exemplo n.º 16
0
        // 移动一个单位到另一个单位的边上(随机位置)
        public bool RandArroundUnit(BaseUnit targetUnit, BaseUnit moveUnit, int range = 8)
        {
            var nodes = GetBFS(targetUnit.Pos, range, moveUnit.AStarMoveMgr.IsCanTraversal, true);
            HashList <GraphNode> RandNodes = new HashList <GraphNode>();

            //节点数量太少,无法摆放军团
            if (nodes.Count <= 1)
            {
                return(false);
            }
            //去掉中心Node
            nodes.RemoveAt(0);
            //获得备用Node
            GraphNode SpareNode = null;

            for (int i = nodes.Count - 1; i > 0; --i)
            {
                var item = nodes[i];
                if (!IsHaveUnit(item) && !IsBlocker(item))
                {
                    SpareNode = item;
                    RandNodes.Add(item);
                }
            }
            //获得随机Node
            GraphNode RandNode;

            RandNode = RandNodes.Rand();
            //获得Final Node
            GraphNode FinalNode = IsHaveUnit(RandNode) || IsBlocker(RandNode) ? SpareNode : RandNode;

            if (FinalNode != null)
            {
                moveUnit.AStarMoveMgr.SetToNode(FinalNode);
                moveUnit.MoveMgr.RandRotationY();
                return(true);
            }
            //进入递归
            else
            {
                return(RandArroundUnit(targetUnit, moveUnit, range + 1));
            }
        }
Exemplo n.º 17
0
 private void SetMoveTarget(TState state, BaseUnit unit, GraphNode node)
 {
     //正确性判断
     if (unit != null && !MoveTargetStateToUnit.Contains(state))
     {
         CLog.Error("错误!SetMoveTarget,unit != null,但state确是:" + state.ToString());
         return;
     }
     else if (node != null && !MoveTargetStateToNode.Contains(state))
     {
         CLog.Error("错误!SetMoveTarget,node != null,但state确是:" + state.ToString());
         return;
     }
     //执行移动
     if (IsMoveTargetState(state))
     {
         MoveTarget_IsValid = true;
         MoveTarget_State   = state;
         MoveTarget_Node    = node;
         MoveTarget_Unit    = unit;
         var  endState   = MoveTargetStateDatas[state].Item1;
         var  isRange    = MoveTargetStateDatas[state].Item2;
         var  isAction   = MoveTargetStateDatas[state].Item3;
         bool isInRange  = isRange == null ? false : isRange.Invoke();
         bool isInAction = isAction == null ? false : isAction.Invoke();
         if (isInRange && isInAction)
         {
             ChangeState(endState, true, true);
         }
         else if (IsCanMove && !isInRange)
         {
             ExcuteMoveTarget(true);
             SetMoveTargetPosReal(Destination);
             SetMoveTargetPosPreview(null, null, Destination);
         }
         else
         {
             SetMoveTargetPosPreview(unit, node, null);
             ShowPath(true);
         }
     }
 }
Exemplo n.º 18
0
 public TData Add(TData buff, BaseUnit self)
 {
     MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer;
     if (MaxLayer <= 0)
     {
         return(null);
     }
     if (MaxLayer > Layer)
     {
         Buffs.Add(buff);
         buff.OnBeAdded(self);
     }
     else
     {
         Remove(buff);
         Buffs.Add(buff);
         buff.OnBeAdded(self);
     }
     return(buff);
 }
Exemplo n.º 19
0
 public TData Add(TData buff, BaseUnit self, BaseUnit caster, TDBaseSkillData fromSkill)
 {
     MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer;
     if (MaxLayer <= 0)
     {
         return(null);
     }
     if (MaxLayer > Layer)
     {
         BuffList.Add(buff);
         buff.OnBeAdded(self, caster, fromSkill);
     }
     else
     {
         Remove(buff);
         BuffList.Add(buff);
         buff.OnBeAdded(self, caster, fromSkill);
     }
     return(buff);
 }
Exemplo n.º 20
0
        public virtual bool OnExitUnit(BaseUnit arg1)
        {
            //退出后射线检测Unit
            RaycastHit hit;

            if (IsStayInUI &&
                Util.MouseRayCast(out hit, SelectUnitLayerMask))
            {
                BaseUnit unit = hit.collider.GetComponent <BaseUnit>();
                OnEnterUnit(unit);
                return(false);
            }
            else
            {
                IsStayInUnit = false;
                HoverUnit    = null;
                Callback_OnMouseExitUnit?.Invoke(arg1);
                return(true);
            }
        }
Exemplo n.º 21
0
        //创建一个HUDitem,HUDitem会在单位死亡后会自动销毁(DoDestroy)
        public THUD SpawnDurableHUD <THUD>(string prefabName, BaseUnit target = null)
            where THUD : UHUDBar
        {
            if (prefabName.IsInv())
            {
                return(null);
            }
            GameObject tempGO = BaseGlobal.GRMgr.UI.Get(prefabName);

            if (tempGO != null)
            {
                var temp = HUDView.Jump(tempGO, target == null?SelfBaseUnit:target);
                if (temp == null)
                {
                    return(null);
                }
                temp.SetFollowObj(GetNode(temp.NodeType));
                return(temp as THUD);
            }
            return(null);
        }
Exemplo n.º 22
0
        //获得Blocker外围的一层链接Node
        public HashList <GraphNode> GetConnectionsBlocker(BaseUnit unit)
        {
            var blocker = GetBlocker(unit);

            if (blocker.Count == 0)
            {
                blocker.Add(GetNode(unit));
            }
            HashList <GraphNode> ret = new HashList <GraphNode>();

            foreach (var item in blocker)
            {
                item.GetConnections((x) =>
                {
                    if (!blocker.Contains(x))
                    {
                        ret.Add(x);
                    }
                });
            }
            return(ret);
        }
Exemplo n.º 23
0
        // 移动到指定单位
        public bool MoveIntoUnit(BaseUnit unit, float speed)
        {
            if (unit == null)
            {
                return(false);
            }
            if (unit.Pos.IsInv())
            {
                return(false);
            }
            if (unit.MoveMgr == null)
            {
                return(false);
            }
            var node = unit.AStarMoveMgr.CurNode;

            if (node == null)
            {
                return(false);
            }
            IsCanUnitOverlap = true;
            return(StartPath((Vector3)node.position, speed));
        }
Exemplo n.º 24
0
        // 移动到指定单位边上
        public bool MoveToUnit(BaseUnit unit, float speed)
        {
            if (unit == null)
            {
                return(false);
            }
            if (unit == SelfBaseUnit)
            {
                return(false);
            }
            if (unit.Pos.IsInv())
            {
                return(false);
            }
            GraphNode closetNode = AStarMgr.GetClosedNode(SelfBaseUnit, unit.Pos);

            if (closetNode == null)
            {
                return(false);
            }
            IsCanUnitOverlap = false;
            return(StartPath((Vector3)closetNode.position, speed));
        }
Exemplo n.º 25
0
        public static string GetBuffStr(BaseUnit targetUnit, List <string> buff)
        {
            string final = "";

            if (buff != null)
            {
                int index = 0;
                foreach (var item in buff)
                {
                    if (index != 0)
                    {
                        final += "\n";
                    }
                    final += Const.STR_DoubbleSpace + targetUnit.BuffMgr.GetTableDesc(item, true, Const.STR_DoubbleIndent, null, true);
                    index++;
                }
            }
            if (final.IsInv())
            {
                return("");
            }
            return(Util.GetStr("Text_Reward_Buff", final));
        }
Exemplo n.º 26
0
        //当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测
        public bool IsInBlockerRange(BaseUnit unit)
        {
            HashList <GraphNode> connection = new HashList <GraphNode>();

            CurNode.GetConnections(connection.Add);
            HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit);

            if (targetUnitBlocker != null)
            {
                foreach (var item in targetUnitBlocker)
                {
                    if (connection.Contains(item))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName());
            }
            return(false);
        }
Exemplo n.º 27
0
        public int GetMarkedByEnemyCount(BaseUnit owner, TTarget target)
        {
            if (owner == null)
            {
                return(0);
            }
            if (target == null)
            {
                return(0);
            }
            if (!target.IsLive)
            {
                return(0);
            }
            if (!TargetUnits.ContainsKey(target))
            {
                return(0);
            }
            bool ret   = Targets.Contains(target);
            int  count = 0;

            if (ret)
            {
                foreach (var item in TargetUnits[target])
                {
                    if (!item.IsLive)
                    {
                        continue;
                    }
                    if (owner.IsEnemy(item))
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
Exemplo n.º 28
0
        protected virtual void OnTouchDown(Vector3 mousePosition, int i)
        {
            LastMouseDownPos = Input.mousePosition;
            RaycastHit hit;

            MouseRayCast(out hit, SelectUnitLayerMask);
            {
                if (BaseUIUtils.CheckGuiObjects())
                {
                    return;
                }
                LastHitCollider = hit.collider;
                if (i == 1)//右键
                {
                    if (LastHitCollider != null)
                    {
                        BaseUnit tempUnit = LastHitCollider.GetComponent <BaseUnit>();
                        if (tempUnit != null)
                        {
                            RightClickUnit(tempUnit);
                        }
                    }
                }
                else if (i == 0)//左键
                {
                    if (LastHitCollider != null)
                    {
                        BaseUnit tempUnit = LastHitCollider.GetComponent <BaseUnit>();
                        if (tempUnit != null)
                        {
                            SelectUnit(tempUnit);
                            LeftClickUnit(tempUnit);
                        }
                    }
                }
            }
        }
Exemplo n.º 29
0
        public bool IsMarkedByEnemy(BaseUnit owner, TTarget target)
        {
            if (owner == null)
            {
                return(false);
            }
            if (target == null)
            {
                return(false);
            }
            if (!target.IsLive)
            {
                return(false);
            }
            if (!TargetUnits.ContainsKey(target))
            {
                return(false);
            }
            bool ret = Targets.Contains(target);

            if (ret)
            {
                foreach (var item in TargetUnits[target])
                {
                    if (!item.IsLive)
                    {
                        continue;
                    }
                    if (owner.IsEnemy(item))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            return(false);
        }
Exemplo n.º 30
0
            public TData Merge(TData buff, BaseUnit self, BaseUnit caster, TDBaseSkillData fromSkill)
            {
                MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer;
                if (MaxLayer <= 0)
                {
                    return(null);
                }
                TData newBuff = null;

                if (BuffList.Count == 0)
                {
                    newBuff = Add(buff, self, caster, fromSkill);
                }
                else
                {
                    newBuff = BuffList[0];
                    if (newBuff.MergeLayer >= MaxLayer)
                    {
                        return(newBuff);
                    }
                    newBuff.OnMerge(buff, caster, fromSkill);
                }
                return(newBuff);
            }