Ejemplo n.º 1
0
 public void PushSkillMsg(Zone _this, CharacterUseSkillMsg temp)
 {
     _this.skillList.Skills.Add(temp);
     if (_this.SkillTrigger == null)
     {
         _this.SkillTrigger =
             SceneServerControl.Timer.CreateTrigger(DateTime.Now.AddMilliseconds(ObjCharacter.BroadcastCd),
                                                    () => { SkillSend(_this); });
     }
 }
        //使用技能广播
        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);
        }
Ejemplo n.º 3
0
 public void PushSkillMsg(CharacterUseSkillMsg temp)
 {
     mImpl.PushSkillMsg(this, temp);
 }
Ejemplo n.º 4
0
    public void NotifyUseSkill(CharacterUseSkillMsg msg)
    {
        if (ObjManager.Instance == null)
        {
            Logger.Log2Bugly(" ObjManager.Instance =null");
            return;
        }
        if (msg == null || msg.Pos == null || msg.Pos.Pos == null)
        {
            Logger.Log2Bugly("NotifyUseSkill msg =null");
            return;
        }
        var chararcter = ObjManager.Instance.FindCharacterById(msg.CharacterId);

        if (null == chararcter)
        {
            Logger.Warn("NotifyUseSkill Cannot find obj[{0}]", msg.CharacterId);
            return;
        }

        if (chararcter.Dead)
        {
            return;
        }

        //放技能时的坐标
        var p = GameLogic.GetTerrainPosition(GameUtils.DividePrecision(msg.Pos.Pos.x),
                                             GameUtils.DividePrecision(msg.Pos.Pos.y));

        //放技能时的朝向
        var dir = new Vector3(GameUtils.DividePrecision(msg.Pos.Dir.x), 0, GameUtils.DividePrecision(msg.Pos.Dir.y));

        //如果距离差距过大就直接拉过来
        var diff = (chararcter.Position.xz() - p.xz()).magnitude;

        ObjCharacter mainTargetCharacter = null;

        if (chararcter.GetObjType() == OBJ.TYPE.MYPLAYER)
        {
            PlatformHelper.Event("Skill", "Auto", msg.SkillId);
            //调整位置
            if (diff > GameSetting.Instance.MainPlayerSkillPosErrorDistance)
            {
                chararcter.Position = p;
            }

            //调整朝向
            chararcter.TargetDirection = dir;
            {
                var __list1      = msg.TargetObjId;
                var __listCount1 = __list1.Count;
                for (var __i1 = 0; __i1 < __listCount1; ++__i1)
                {
                    var id = __list1[__i1];
                    {
                        var target = ObjManager.Instance.FindCharacterById(id);
                        if (null != target)
                        {
                            mainTargetCharacter = target;
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            if (chararcter.GetObjType() == OBJ.TYPE.OTHERPLAYER)
            {
                if (diff > GameSetting.Instance.OtherPlayerSkillPosErrorDistance)
                {
                    chararcter.Position = p;
                }
            }
            else
            {
                if (diff > GameSetting.Instance.NPCSkillPosErrorDistance)
                {
                    chararcter.DelayedMove = p;
                }
            }

            var adjustDir = false;
            {
                var __list2      = msg.TargetObjId;
                var __listCount2 = __list2.Count;
                for (var __i2 = 0; __i2 < __listCount2; ++__i2)
                {
                    var id = __list2[__i2];
                    {
                        var target = ObjManager.Instance.FindCharacterById(id);
                        if (null != target)
                        {
                            mainTargetCharacter = target;
                            chararcter.Target   = target;
                            if (chararcter.GetObjType() == OBJ.TYPE.NPC)
                            {
                                if (((ObjNPC)chararcter).TowardPlayer)
                                {
                                    chararcter.FaceTo(target.Position);
                                }
                            }
                            else
                            {
                                chararcter.FaceTo(target.Position);
                            }
                            adjustDir = true;
                            break;
                        }
                    }
                }
            }
            if (!adjustDir)
            {
                chararcter.TargetDirection = dir;
            }
        }

        var skillData = Table.GetSkill(msg.SkillId);

        if (null == skillData)
        {
            Logger.Fatal("Can't find skill[{0}]", msg.SkillId);
            return;
        }

        //放技能
        chararcter.UseSkill(skillData, msg.TargetObjId);

        if (chararcter.GetObjType() == OBJ.TYPE.MYPLAYER)
        {
            var e = new SkillReleaseNetBack(skillData.Id, true);
            EventDispatcher.Instance.DispatchEvent(e);
        }

        if (ObjManager.Instance.MyPlayer == null)
        {
            Logger.Log2Bugly("ObjManager.Instance.MyPlayer == null");
            return;
        }

        if (msg.CharacterId != ObjManager.Instance.MyPlayer.GetObjId() &&
            msg.TargetObjId.Contains(ObjManager.Instance.MyPlayer.GetObjId()))
        {
            PlayerDataManager.Instance.SetSelectTargetData(chararcter, 1);
        }

        if (msg.CharacterId == ObjManager.Instance.MyPlayer.GetObjId() &&
            ObjManager.Instance.MyPlayer != mainTargetCharacter &&
            mainTargetCharacter != null &&
            mainTargetCharacter.Dead == false)
        {
            PlayerDataManager.Instance.SetSelectTargetData(mainTargetCharacter, 2);
        }
        //Logger.Info("NotifyUseSkill Obj[{0}] skill[{1}]", msg.CharacterId, msg.SkillId);
    }
Ejemplo n.º 5
0
    public IEnumerator SendUseSkillRequestCoroutine(ulong objId, int skillId, ulong targetId)
    {
        //Logger.Error("SendUseSkillRequestCoroutine ------Send--- {1}--- {0}", Game.Instance.ServerTime, skillId);
        if (skillId == PlayerDataManager.Instance.GetSkillNoWeapon())
        {
            skillId = PlayerDataManager.Instance.GetNormalSkill(false);
        }

        var            requset     = new CharacterUseSkillMsg();
        var            obj         = ObjManager.Instance.FindCharacterById(objId);
        var            skillStates = PlayerDataManager.Instance.PlayerDataModel.SkillData.SkillStates;
        SkillStateData skillState;

        if (skillStates.TryGetValue(skillId, out skillState))
        {
            skillState.State = SkillState.Send;
        }
        else
        {
            skillState         = new SkillStateData();
            skillState.SkillId = skillId;
            skillState.State   = SkillState.Send;
            skillStates.Add(skillId, skillState);
        }

        var x    = obj.Position.x;
        var z    = obj.Position.z;
        var dirX = obj.TargetDirection.x;
        var dirZ = obj.TargetDirection.z;

        requset.CharacterId = objId;
        requset.SkillId     = skillId;
        requset.TargetObjId.Add(targetId);
        requset.Pos = new PositionData
        {
            Pos = new Vector2Int32
            {
                x = GameUtils.MultiplyPrecision(x),
                y = GameUtils.MultiplyPrecision(z)
            },
            Dir = new Vector2Int32
            {
                x = GameUtils.MultiplyPrecision(dirX),
                y = GameUtils.MultiplyPrecision(dirZ)
            }
        };
        Logger.Info(".......SendUseSkillRequest.....objId : {0}..skillId : {1}", objId, skillId);
        var msg = Instance.SendUseSkillRequest(requset);

        yield return(msg.SendAndWaitUntilDone());

        skillState.State = SkillState.Rece;
        //Logger.Error("SendUseSkillRequestCoroutine ------Rece---{1}--- {0}", Game.Instance.ServerTime,skillId);
        if (msg.State == MessageState.Reply)
        {
            if (msg.ErrorCode == (int)ErrorCodes.OK)
            {
                EventDispatcher.Instance.DispatchEvent(new UiEventChangeOutLineTime());
                if (msg.Response.Items.Count < 1)
                {
                    yield break;
                }
                skillId = msg.Response.Items[0];
                if (obj.GetObjType() == OBJ.TYPE.MYPLAYER)
                {
                    EventDispatcher.Instance.DispatchEvent(new UIEvent_UseSkill(skillId));
                    //SkillReleaseNetBack e = new SkillReleaseNetBack(skillId, true);
                    //EventDispatcher.Instance.DispatchEvent(e);
                }
                yield break;
            }
            if (msg.ErrorCode == (int)ErrorCodes.Error_CharacterDie ||
                msg.ErrorCode == (int)ErrorCodes.Error_SkillNotUse)
            {
//异步逻辑可能发送接受不一致
                Logger.Info("[DoUseSkill]  SkillId : {0}  msg.ErrorCode={1}", skillId, msg.ErrorCode.ToString());
            }
        }
        //技能释放返回错误
        if (obj.GetObjType() == OBJ.TYPE.MYPLAYER)
        {
            var ee = new SkillReleaseNetBack(skillId, false);
            EventDispatcher.Instance.DispatchEvent(ee);
        }
    }