// 出售物品 public void ReqSellItem(long itemID, int count) { PUseCommonItem data = new PUseCommonItem(); data.comItem.Add(new PComItem { id = itemID, num = count, }); Net.Send(eCommand.SALE_GOOD_TOSYS, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.SALE_GOOD_TOSYS)) { return; } ItemInfo info = GetItem(itemID); if (info != null) { AddMoney(info.Cfg.Price * count, PriceType.MONEY); } UseItem(itemID, count); UIManager.Instance.RefreshWindow <UINewBagView>(); }); }
// 请求取消升级建筑 public void RequestCancelUpgradeBuilding(long buildingID) { BuildingInfo infoSend = GetBuilding(buildingID); if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = infoSend.Cfg.BuildingType; Net.Send(eCommand.CANCLE_UPGRADE_BUILD, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.CANCLE_UPGRADE_BUILD)) { return; } // 返还资源 UserManager.Instance.AddMoney(Mathf.FloorToInt(infoSend.CfgLevel.CostStone * GameConfig.CITY_BUILDING_CANCEL_BACK), PriceType.STONE); UserManager.Instance.AddMoney(Mathf.FloorToInt(infoSend.CfgLevel.CostWood * GameConfig.CITY_BUILDING_CANCEL_BACK), PriceType.WOOD); infoSend.LevelUpRemainTime.Reset(); // TODO 返还资源由服务器推送 RefreshUI(buildingID); }); }
// 设置阵型 public void ReqSetFormation() { PSetLineUp data = new PSetLineUp(); data.lineType = eLineUpType.BT_PVE; int index = 0; foreach (var item in PVEHeroList) { ++index; data.positionHero.Add(new PPosionInfo { pos = index, arg = item.EntityID, }); } Net.Send(eCommand.SET_LINE_UP, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.SET_LINE_UP)) { return; } }); }
public void ShouldOnlyAllowBetweenZeroAndOneHundred() { var answer = new CommonAnswer(); Assert.Throws <InvalidGradeException>(() => { answer.Grade = -1; }); Assert.Throws <InvalidGradeException>(() => { answer.Grade = 101; }); }
private void OnMsgWhichGameServer(byte[] buffer) { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.WHICH_GAME_SERVER)) { // 重新连接登录服务器(此时登录服务器已经断开连接) ServerManager.Instance.ReConnectToLoginServer(); return; } ; // 选择游戏服务器成功,可以直接连接游戏服务器 ServerManager.Instance.ConnectGameServer(); }
private void OnMsgJoin(byte[] buffer) { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.JOIN)) { return; } // 此时正式进入游戏 Game.Instance.IsInGame = true; NetworkManager.Instance.NeedToSendHeartBeat = true; EventDispatcher.TriggerEvent(EventID.EVENT_UI_LOGIN_OK); UserManager.Instance.RequestUserInfo(); }
private void UseItem(int itemCfgID, int count) { PCMInt2 data = new PCMInt2(); data.arg = itemCfgID; data.arg2 = count; NetworkManager.Instance.Send(eCommand.SYS_REDUCE_GOOD, data, (byte[] buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (ret.err_code != 0) { Log.Error("GM使用物品失败 {0}", ret.err_code); return; } Log.Info("GM使用物品成功"); if (itemCfgID == GameConfig.ITEM_CONFIG_ID_MONEY) { UserManager.Instance.Money = Mathf.Max(UserManager.Instance.Money - count, 0); } else if (itemCfgID == GameConfig.ITEM_CONFIG_ID_WOOD) { UserManager.Instance.Money = Mathf.Max(UserManager.Instance.Wood - count, 0); } else if (itemCfgID == GameConfig.ITEM_CONFIG_ID_STONE) { UserManager.Instance.Money = Mathf.Max(UserManager.Instance.Stone - count, 0); } else if (itemCfgID == GameConfig.ITEM_CONFIG_ID_GOLD) { UserManager.Instance.Money = Mathf.Max(UserManager.Instance.Gold - count, 0); } else { ItemInfo info = UserManager.Instance.GetItemByConfigID(itemCfgID); if (info != null) { info.Number = Mathf.Max(info.Number - count, 0); } } EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE); }); }
// 向服务器请求重置挑战次数 public void RequestResetFightCount(int levelID) { PCMInt data = new PCMInt(); data.arg = levelID; Net.Send(eCommand.BUY_ELITE_COUNT, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.BUY_ELITE_COUNT)) { return; } // 重置攻打次数 LevelInfo info = GetLevelInfo(levelID); if (info != null) { info.fightCount = 0; } UserManager.Instance.CostMoney(GameConfig.PVE_RESET_FIGHT_COUNT_COST, PriceType.GOLD); UIManager.Instance.RefreshWindow <UINewPVELevelInfoView>(); EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE); }); }
public void RequestSkillUpgrade(long heroID, int skillID, int index) { HeroInfo info = GetHeroInfo(heroID); if (info == null) { return; } SkillInfo skillInfo = info.GetSkillByID(skillID); int level = 1; if (skillInfo != null) { level = skillInfo.Level; } if (level + 1 > info.Level) { UIUtil.ShowMsgFormat("MSG_HERO_SKILL_NEED_HERO_LEVEL", info.Level + 1); return; } int moneyCost = SkillInfo.GetUpgradeCost(index, level); if (UserManager.Instance.Money < moneyCost) { UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_MONEY_LIMIT"); return; } if (UserManager.Instance.GetCurrentSkillPoint() <= 0) { UIUtil.ShowMsgFormat("MSG_HERO_SKILL_POINT_LIMIT"); return; } PSkill builder = new PSkill(); builder.heroId = heroID; builder.cfgId = skillID; NetworkManager.Instance.Send(eCommand.UPGRADE_SKILL, builder, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.UPGRADE_SKILL)) { return; } // 减去消耗的金钱和技能点 Money -= moneyCost; UseSkillPoint(); if (skillInfo != null) { ++skillInfo.Level; } // 刷新英雄技能界面 UIManager.Instance.RefreshWindow <UINewHeroView>(); UIManager.Instance.RefreshWindow <UINewHeroListView>(); // 刷新主界面的金钱数据 EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE); }); }