//广播自己位置
        public void BroadcastSelfPostion(ObjCharacter _this)
        {
            if (!_this.mActive)
            {
                return;
            }
            if (null == _this.Zone)
            {
                return;
            }
            var msg = new SyncPostionMsg();

            msg.ObjId = _this.ObjId;
            msg.Pos   = new PositionData
            {
                Pos = new Vector2Int32
                {
                    x = Utility.MultiplyPrecision(_this.GetPosition().X),
                    y = Utility.MultiplyPrecision(_this.GetPosition().Y)
                },
                Dir = new Vector2Int32
                {
                    x = Utility.MultiplyPrecision(_this.GetDirection().X),
                    y = Utility.MultiplyPrecision(_this.GetDirection().Y)
                }
            };

            SceneServer.Instance.ServerControl.SyncStopMove(_this.EnumAllVisiblePlayerIdExclude(), msg);
        }
        //使用技能广播
        public void BroadcastUseSkill(ObjCharacter _this, int skillId, ObjCharacter obj)
        {
            if (!_this.mActive)
            {
                return;
            }
            if (null == _this.Zone)
            {
                return;
            }
            ulong targetId = 0;

            if (obj != null)
            {
                targetId = obj.ObjId;
            }
            var msg = new CharacterUseSkillMsg();

            msg.CharacterId = _this.ObjId;
            msg.SkillId     = skillId;
            msg.TargetObjId.Add(targetId);
            msg.Pos = new PositionData
            {
                Pos = new Vector2Int32
                {
                    x = Utility.MultiplyPrecision(_this.GetPosition().X),
                    y = Utility.MultiplyPrecision(_this.GetPosition().Y)
                },
                Dir = new Vector2Int32
                {
                    x = Utility.MultiplyPrecision(_this.GetDirection().X),
                    y = Utility.MultiplyPrecision(_this.GetDirection().Y)
                }
            };

            if (ObjCharacter.BroadcastType == 1)
            {
                _this.Zone.PushSkillMsg(msg);
                return;
            }
            SceneServer.Instance.ServerControl.NotifyUseSkill(_this.EnumAllVisiblePlayerIdExclude(), msg);
        }
Exemplo n.º 3
0
        public void CreateNpc(ObjCharacter Character, int dataId, bool canRelive = false, int level = -1)
        {
            var scene = Character.Scene;

            if (null == scene)
            {
                return;
            }

            var npc = scene.CreateNpc(null, dataId, Character.GetPosition(), Vector2.UnitX, "GM_Create_" + dataId, level);

            if (null != npc)
            {
                npc.CanRelive = canRelive;
            }
        }
Exemplo n.º 4
0
 public void AdjustPlayer(TriggerArea _this, ObjCharacter player)
 {
     if (IsInArea(_this, player.GetPosition()))
     {
         if (!_this.mCharacterList.Contains(player))
         {
             Add(_this, player);
         }
     }
     else
     {
         if (_this.mCharacterList.Contains(player))
         {
             Remove(_this, player);
         }
     }
 }
Exemplo n.º 5
0
        public static bool AddCollider(Coroutine co,
                                       SceneObstacle obstacle,
                                       ObjCharacter obj,
                                       float radius,
                                       AsyncReturnValue <uint> result)
        {
            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() =>
                {
                    var b        = obstacle.AddCollider(obj.GetPosition(), radius);
                    result.Value = b;

                    if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                    {
                        SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                    }
                });
            }

            return(true);
        }
Exemplo n.º 6
0
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            ObjCharacter enemy = null;

            //判断敌人是否存在
            if (npc.TableAI == null)
            {
                enemy = npc.GetMaxHatre();
            }
            else
            {
                enemy = GetAttackTarget(npc);
            }

            //判断敌人是否存在

            if (null == enemy)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断敌人是否有效
            if (enemy.IsDead() || !enemy.Active)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断是否太远了
            var dis = (npc.GetPosition() - mBackPosition).Length();

            if (npc.TableNpc.MaxCombatDistance > 0 && dis >= npc.TableNpc.MaxCombatDistance)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //如果有普通
            if (null != mTableNormalSkill)
            {
                //跟着敌人打
                if ((npc.GetPosition() - enemy.GetPosition()).Length() <= mSkillDistance)
                {
                    npc.TurnFaceTo(enemy.GetPosition());
                    if (npc.IsMoving())
                    {
                        GenNextNormalAttackTime(100);
                        npc.StopMove();
                    }
                    if (DateTime.Now >= mNextNormalAttackTime)
                    {
                        npc.Seperate(enemy, mSkillDistance / 3);
                        var skillId = npc.NormalSkillId;
                        npc.UseSkill(ref skillId, enemy);
                        GenNextNormalAttackTime();
                        mNoMoveTime = 0; //攻击了一次就把自己站在原地的累计时间清空
                    }
                }
                else
                {
                    var targetPos = npc.CalculatePostionToEnemy(enemy, mSkillDistance / 3);
                    if (MoveResult.CannotReach == npc.MoveTo(targetPos))
                    {
//如果长时间无法到达目的地说明卡怪了, 就回去
                        mNoMoveTime += delta;
                        if (mNoMoveTime >= MAX_NO_MOVE_TIME)
                        {
                            npc.EnterState(BehaviorState.GoHome);
                        }
                    }
                    else
                    {
                        mNoMoveTime = 0;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void TryToCallPartner(ObjNPC npc, ObjCharacter enemy, float distSqr = 100)
        {
            try
            {
                if (enemy != null)
                {
                    foreach (ObjBase o in npc.Zone.EnumAllVisibleObj())
                    {
                        try
                        {
                            if (!(o is ObjNPC))
                            {
                                continue;
                            }

                            var obj = o as ObjNPC;

                            if (!obj.Active)
                            {
                                continue;
                            }

                            if (obj.CurrentState != BehaviorState.Idle)
                            {
                                continue;
                            }

                            if (obj.GetObjType() != ObjType.NPC)
                            {
                                continue;
                            }

                            if (!obj.IsVisibleTo(enemy))
                            {
                                continue;
                            }

                            if (obj.tbSceneNpc == null || npc.tbSceneNpc == null)
                            {
                                continue;
                            }

                            if (obj.tbSceneNpc.ChouHenGroupId != npc.tbSceneNpc.ChouHenGroupId)
                            {
                                continue;
                            }

                            if (obj.mCamp != npc.mCamp)
                            {
                                continue;
                            }

                            if ((obj.GetPosition() - enemy.GetPosition()).LengthSquared() > distSqr)
                            {
                                continue;
                            }

                            obj.EnterState(BehaviorState.Combat);
                            obj.PushHatre(enemy, 1);
                            obj.AddEnemy(enemy.ObjId);
                            enemy.AddEnemy(obj.ObjId);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch { }
        }
Exemplo n.º 8
0
        public void Seperate(ObjNPC _this, ObjCharacter enemy, float dist)
        {
            if (ObjNPC.PreCalculatedClockwiseRotation == null)
            {
                CalculateRotation();
            }

            var          move = false;
            ObjCharacter npc;

            // 如果人很多的话,减小距离
            var d = 2 * Math.PI * dist / enemy.EnemyList.Count;
            var t = Math.Min(d * d, 0.25f);
            var s = 0;
            var i = 0;

            for (; i < enemy.EnemyList.Count; i++)
            {
                var npcId = enemy.EnemyList[i];
                if (npcId == _this.ObjId)
                {
                    break;
                }

                npc = _this.Scene.FindCharacter(npcId);
                if (npc == null)
                {
                    enemy.EnemyList.RemoveAt(i);
                    --i;
                    continue;
                }
                var distSqr = (npc.GetPosition() - _this.GetPosition()).LengthSquared();

                if (distSqr < 1)
                {
                    if (distSqr < t)
                    {
                        move = true;
                    }

                    s++;
                }
            }


            if (s >= 36)
            {
                // 怪实在太多了,随便找个地方给他吧
                s = MyRandom.Random(3);
            }

            if (move)
            {
                var pos = _this.GetPosition();
                var p   = (pos - enemy.GetPosition());

                //顺时针旋转
                if (_this.ObjId % 2 == 0)
                {
                    var x = Vector2.Dot(p, ObjNPC.PreCalculatedClockwiseRotation[2 * s]);
                    var y = Vector2.Dot(p, ObjNPC.PreCalculatedClockwiseRotation[2 * s + 1]);
                    pos = enemy.GetPosition() + new Vector2(x, y);
                }
                else
                {
                    var x = Vector2.Dot(p, ObjNPC.PreCalculatedCounterClockwiseRotation[2 * s]);
                    var y = Vector2.Dot(p, ObjNPC.PreCalculatedCounterClockwiseRotation[2 * s + 1]);
                    pos = enemy.GetPosition() + new Vector2(x, y);
                }

                if (enemy.Scene.ValidPosition(pos))
                {
                    _this.SetPosition(pos);
                }
            }
        }