void ParseMessage(object sender, MessageEventArgs e) { SocketMessage bsObj = JsonConvert.DeserializeObject <SocketMessage>(e.Data); ping = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - bsObj.sendTime; switch (bsObj.type) { case EnemiesDataMessage.TYPE: EnemiesDataMessage enemiesData = JsonConvert.DeserializeObject <EnemiesDataMessage>(bsObj.data); lock (x) { enemies = new List <Enemy>(); if (enemiesData.enemiesList != null) { foreach (EnemyDummy dummy in enemiesData.enemiesList) { enemies.Add(Enemy.createFromDummy(dummy)); } } } break; case PositionChangedMessage.TYPE: PositionChangedMessage positionChange = JsonConvert.DeserializeObject <PositionChangedMessage>(bsObj.data); GamePlayer gamePlayer = currentGame.gamePlayers.getPlayer(positionChange.playerId); gamePlayer.position = positionChange.position; break; case PlayerScoreMessage.TYPE: PlayerScoreMessage data = JsonConvert.DeserializeObject <PlayerScoreMessage>(bsObj.data); currentGame.gamePlayers = data.players; break; case BulletsDataReceiveMessage.TYPE: BulletsDataReceiveMessage bulletsData = JsonConvert.DeserializeObject <BulletsDataReceiveMessage>(bsObj.data); lock (bulletLock) { bullets = new List <Bullet>(); if (bulletsData.bulletList != null) { bullets = bulletsData.bulletList; } } break; case PlayerAngleMessage.TYPE: PlayerAngleMessage angleData = JsonConvert.DeserializeObject <PlayerAngleMessage>(bsObj.data); angle = angleData.angle; break; case BestScoreMessage.TYPE: BestScoreMessage scoreData = JsonConvert.DeserializeObject <BestScoreMessage>(bsObj.data); if (currentGame != null) { currentGame.bestScore = scoreData.score; } break; case GoldenToothMessage.TYPE: GoldenToothMessage goldenToothData = JsonConvert.DeserializeObject <GoldenToothMessage>(bsObj.data); if (goldenTooth == null) { goldenTooth = new GoldenTooth(); } goldenTooth.position = goldenToothData.position; break; case PlayerDataMessage.TYPE: PlayerDataMessage playerData = JsonConvert.DeserializeObject <PlayerDataMessage>(bsObj.data); if (currentPlayer == null) { currentPlayer = new Player(playerData.id, playerData.name); } break; case GameDataMessage.TYPE: GameFacade game = JsonConvert.DeserializeObject <GameFacade>(bsObj.data); if (currentGame == null) { currentGame = new GameFacade(); } currentGame.name = game.name; lock (playerLock) { if (game.gamePlayers.P1 != null) { currentGame.gamePlayers.P1 = game.gamePlayers.P1; IMoveStrategy strategy = new P1MoveStrategy(); currentGame.gamePlayers.P1.moveLeft = new MoveLeftCommand(strategy, game.gamePlayers.P1.position); currentGame.gamePlayers.P1.moveRight = new MoveRightCommand(strategy, game.gamePlayers.P1.position); } else { currentGame.gamePlayers.P1 = null; } if (game.gamePlayers.P2 != null) { currentGame.gamePlayers.P2 = game.gamePlayers.P2; IMoveStrategy strategy = new P2MoveStrategy(); currentGame.gamePlayers.P2.moveLeft = new MoveLeftCommand(strategy, game.gamePlayers.P2.position); currentGame.gamePlayers.P2.moveRight = new MoveRightCommand(strategy, game.gamePlayers.P2.position); } else { currentGame.gamePlayers.P2 = null; } if (game.gamePlayers.P3 != null) { currentGame.gamePlayers.P3 = game.gamePlayers.P3; IMoveStrategy strategy = new P3MoveStrategy(); currentGame.gamePlayers.P3.moveLeft = new MoveLeftCommand(strategy, game.gamePlayers.P3.position); currentGame.gamePlayers.P3.moveRight = new MoveRightCommand(strategy, game.gamePlayers.P3.position); } else { currentGame.gamePlayers.P3 = null; } if (game.gamePlayers.P4 != null) { currentGame.gamePlayers.P4 = game.gamePlayers.P4; IMoveStrategy strategy = new P4MoveStrategy(); currentGame.gamePlayers.P4.moveLeft = new MoveLeftCommand(strategy, game.gamePlayers.P4.position); currentGame.gamePlayers.P4.moveRight = new MoveRightCommand(strategy, game.gamePlayers.P4.position); } else { currentGame.gamePlayers.P4 = null; } } break; } }
public void RefreshData(PlayerDataMessage message) { hertTimestamp = message.heartTime / 1000; coinNum = message.gold; heartNum = message.heart; starNum = message.star; nickName = message.name; userId = message.uid; eliminateLevel = message.level; if (message.sevenDay != null && message.sevenDay.sevenDayInfo != null) { indexDay = message.sevenDay.sevenDayInfo.index; awardState = message.sevenDay.sevenDayInfo.state; } else { awardState = 2; } propsDic = new Dictionary <string, config.PropItem>(); foreach (PlayerDataMessage.PropItem item in message.items) { PropItem prop = GameMainManager.Instance.configManager.propsConfig.GetItem(item.itemId); if (prop != null) { prop.count = item.count; prop.uuid = item.uuid; prop.vanishTime = item.vanishTime; } propsDic.Add(item.itemId, prop); } //--------------------------------------- if (message.roles != null) { foreach (PlayerDataMessage.RoleData item in message.roles) { SetRoleState(item.roleId, (RoleState)item.status); } } if (message.stories != null) { foreach (PlayerDataMessage.StoryData story in message.stories) { if (!complatedQuests.ContainsKey(story.storyId)) { complatedQuests.Add(story.storyId, 0); } } } if (!string.IsNullOrEmpty(message.roleId)) { role = GameMainManager.Instance.configManager.roleConfig.GetItem(message.roleId).Clone(); } questId = message.storyid;//任务id存到角色数据中有了角色再保存数据 if (!string.IsNullOrEmpty(nextQuestId)) { questId = nextQuestId; } ability = new config.Ability(message.discipline, message.loyalty, message.wisdom); totalExp = int.Parse(message.storyExp); currExp = int.Parse(message.lvExp); level = message.storyLv == 0?1: message.storyLv; //----------------------------------- dirty = false; SaveData(); Messenger.Broadcast(ELocalMsgID.RefreshBaseData); }
internal static void GetPlayerData() { if (Server.IsSocketConnected() == false || Core.Player == null) { return; } LocalPlayer player = Core.Player; Dictionary <ClassJobType, ushort> playerLevels = player.Levels; Stats playerStats = player.Stats; PlayerDataMessage playerDataMessage = new PlayerDataMessage(); playerDataMessage.CoreAuthKey = Settings.Instance.CoreAuthKey; playerDataMessage.PlayerName = player.Name; playerDataMessage.CurrentJob = player.CurrentJob.ToString(); playerDataMessage.Location = player.Location.ToString(); playerDataMessage.IdLocation = player.IdLocation; playerDataMessage.FateId = player.FateId; playerDataMessage.CurrentHealth = player.CurrentHealth; playerDataMessage.MaxHealth = player.MaxHealth; playerDataMessage.CurrentMana = player.CurrentMana; playerDataMessage.MaxMana = player.MaxMana; playerDataMessage.CurrentTP = player.CurrentTP; playerDataMessage.MaxTP = player.MaxTP; playerDataMessage.CurrentExperience = Experience.CurrentExperience; playerDataMessage.CurrentRestedExperience = Experience.CurrentRestedExperience; playerDataMessage.ExperienceRequired = Experience.ExperienceRequired; playerDataMessage.GladiatorLevel = playerLevels[ClassJobType.Gladiator]; playerDataMessage.PugilistLevel = playerLevels[ClassJobType.Pugilist]; playerDataMessage.MarauderLevel = playerLevels[ClassJobType.Marauder]; playerDataMessage.LancerLevel = playerLevels[ClassJobType.Lancer]; playerDataMessage.ArcherLevel = playerLevels[ClassJobType.Archer]; playerDataMessage.ConjurerLevel = playerLevels[ClassJobType.Conjurer]; playerDataMessage.ThaumaturgeLevel = playerLevels[ClassJobType.Thaumaturge]; playerDataMessage.CarpenterLevel = playerLevels[ClassJobType.Carpenter]; playerDataMessage.BlacksmithLevel = playerLevels[ClassJobType.Blacksmith]; playerDataMessage.ArmorerLevel = playerLevels[ClassJobType.Armorer]; playerDataMessage.GoldsmithLevel = playerLevels[ClassJobType.Goldsmith]; playerDataMessage.LeatherworkerLevel = playerLevels[ClassJobType.Leatherworker]; playerDataMessage.WeaverLevel = playerLevels[ClassJobType.Weaver]; playerDataMessage.AlchemistLevel = playerLevels[ClassJobType.Alchemist]; playerDataMessage.CulinarianLevel = playerLevels[ClassJobType.Culinarian]; playerDataMessage.MinerLevel = playerLevels[ClassJobType.Miner]; playerDataMessage.BotanistLevel = playerLevels[ClassJobType.Botanist]; playerDataMessage.FisherLevel = playerLevels[ClassJobType.Fisher]; playerDataMessage.ArcanistLevel = playerLevels[ClassJobType.Arcanist]; playerDataMessage.RogueLevel = playerLevels[ClassJobType.Rogue]; playerDataMessage.MachinistLevel = playerLevels[ClassJobType.Machinist]; playerDataMessage.DarkKnightLevel = playerLevels[ClassJobType.DarkKnight]; playerDataMessage.AstrologianLevel = playerLevels[ClassJobType.Astrologian]; playerDataMessage.SamuraiLevel = playerLevels[ClassJobType.Samurai]; playerDataMessage.RedMageLevel = playerLevels[ClassJobType.RedMage]; playerDataMessage.Strength = playerStats.Strength; playerDataMessage.Dexterity = playerStats.Dexterity; playerDataMessage.Vitality = playerStats.Vitality; playerDataMessage.Intelligence = playerStats.Intelligence; playerDataMessage.Mind = playerStats.Mind; playerDataMessage.Piety = playerStats.Piety; playerDataMessage.FireResistance = 0; //playerStats.FireResistance playerDataMessage.IceResistance = 0; //playerStats.IceResistance playerDataMessage.WindResistance = 0; //playerStats.WindResistance playerDataMessage.EarthResistance = 0; //playerStats.EarthResistance playerDataMessage.LightningResistance = 0; //playerStats.LightningResistance playerDataMessage.WaterResistance = 0; //playerStats.WaterResistance playerDataMessage.Accuracy = 0; //playerStats.Accuracy playerDataMessage.CriticalHitRate = 0; //playerStats.CriticalHitRate playerDataMessage.Determination = 0; //playerStats.Determination playerDataMessage.Defense = playerStats.Defense; playerDataMessage.Parry = 0; //playerStats.Parry playerDataMessage.MagicDefense = playerStats.MagicDefense; playerDataMessage.AttackPower = playerStats.AttackPower; playerDataMessage.SkillSpeed = playerStats.SkillSpeed; playerDataMessage.Gathering = playerStats.Gathering; playerDataMessage.Perception = playerStats.Perception; playerDataMessage.SlowResistance = 0; //playerStats.SlowResistance playerDataMessage.SilenceResistance = 0; //playerStats.SilenceResistance playerDataMessage.BlindResistance = 0; //playerStats.BlindResistance playerDataMessage.PoisonResistance = 0; //playerStats.PoisonResistance playerDataMessage.StunResistance = 0; //playerStats.StunResistance playerDataMessage.SleepResistance = 0; //playerStats.SleepResistance playerDataMessage.BindResistance = 0; //playerStats.BindResistance playerDataMessage.HeavyResistance = 0; //playerStats.HeavyResistance Server.QueueMessage(JsonConvert.SerializeObject(playerDataMessage)); }