diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs b/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs index 5753ca0387..4794d4f01e 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs @@ -37,6 +37,11 @@ namespace BrewMonster { OnClickBtnEscape(); } + + if (Input.GetKeyDown(KeyCode.F4)) + { + CmdFly(true); + } } /// diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs index 63a959a850..e544775d8d 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs @@ -1472,6 +1472,15 @@ namespace CSNetwork.S2CCommand this.z = z; } }; + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_use_item + { + public byte where; + public byte byCount; + public ushort index; + public int item_id; + }; } // Player and NPC state \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs index 2e92607e34..7c2b26dbbf 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs @@ -719,7 +719,7 @@ namespace CSNetwork.C2SCommand // BYTE* pBuf = (BYTE*)a_malloctemp(iSize); // if(!pBuf) return; // - // ((cmd_header*)pBuf)->cmd = C2S::AUTO_TEAM_SET_GOAL; + // ((cmd_header*)pBuf).cmd = C2S::AUTO_TEAM_SET_GOAL; // // cmd_auto_team_set_goal pCmd = (cmd_auto_team_set_goal*)(pBuf + sizeof(cmd_header)); cmd_auto_team_set_goal pCmd = new cmd_auto_team_set_goal() @@ -730,7 +730,7 @@ namespace CSNetwork.C2SCommand }; // - // g_pGame->GetGameSession()->SendGameData(pBuf, iSize); + // g_pGame.GetGameSession().SendGameData(pBuf, iSize); // // a_freetemp(pBuf); // var cmd = new CMD_GetAllData @@ -764,12 +764,12 @@ namespace CSNetwork.C2SCommand // if (!pBuf) // return; - // ((cmd_header*)pBuf)->cmd = C2S::GOTO; + // ((cmd_header*)pBuf).cmd = C2S::GOTO; // // cmd_goto* pCmd = (cmd_goto*)(pBuf + sizeof (cmd_header)); - // pCmd->vDest.Set(x, y, z); + // pCmd.vDest.Set(x, y, z); // - // g_pGame->GetGameSession()->SendGameData(pBuf, iSize); + // g_pGame.GetGameSession().SendGameData(pBuf, iSize); // // a_freetemp(pBuf); @@ -778,5 +778,15 @@ namespace CSNetwork.C2SCommand return SerializeCommand(CommandID.GOTO, cmd); } + + public static Octets CreateUseItemCmd(byte byPackage, byte bySlot, int tid, byte byCount) + { + cmd_use_item pCmd = new cmd_use_item(); + pCmd.where = byPackage; + pCmd.index = bySlot; + pCmd.item_id = tid; + pCmd.byCount = byCount; + return SerializeCommand(CommandID.USE_ITEM, pCmd); + } } } diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index 99a5589845..769af55162 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -1390,5 +1390,11 @@ namespace CSNetwork SendProtocol(gamedatasend); } + public void c2s_SendCmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateUseItemCmd(byPackage, bySlot, tid, byCount); + SendProtocol(gamedatasend); + } } } \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 89d4492329..43101ce8c5 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -409,5 +409,10 @@ namespace BrewMonster.Network { Instance._gameSession.c2s_CmdGoto(x, y, z); } + + public static void c2s_CmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount) + { + Instance._gameSession.c2s_SendCmdUseItem(byPackage, bySlot, tid, byCount); + } } } \ No newline at end of file diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index d219a82df1..bcb244cda4 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -595,15 +595,15 @@ namespace BrewMonster // other goblin skills should be set public cool down, 1 second /* for (i = 0; i < m_aGoblinSkills.GetSize(); i++) { - if (m_aGoblinSkills[i] && m_aGoblinSkills[i]->GetCoolingCnt() == 0) - m_aGoblinSkills[i]->StartCooling(GetCoolTime(GP_CT_CAST_ELF_SKILL), GetCoolTime(GP_CT_CAST_ELF_SKILL)); + if (m_aGoblinSkills[i] && m_aGoblinSkills[i].GetCoolingCnt() == 0) + m_aGoblinSkills[i].StartCooling(GetCoolTime(GP_CT_CAST_ELF_SKILL), GetCoolTime(GP_CT_CAST_ELF_SKILL)); }*/ /* for (i = 0; i < m_aPsSkills.Count; i++) { CECSkill pSkill = GetPassiveSkillByIndex(i); - if (pSkill && (pSkill->GetCommonCoolDown() & (1 << (pCmd->cooldown_index - GP_CT_SKILLCOMMONCOOLDOWN0)))) - pSkill->StartCooling(GetCoolTime(pCmd->cooldown_index), GetCoolTime(pCmd->cooldown_index)); + if (pSkill && (pSkill.GetCommonCoolDown() & (1 << (pCmd.cooldown_index - GP_CT_SKILLCOMMONCOOLDOWN0)))) + pSkill.StartCooling(GetCoolTime(pCmd.cooldown_index), GetCoolTime(pCmd.cooldown_index)); }*/ } @@ -622,7 +622,7 @@ namespace BrewMonster std::map < unsigned int, CECSkill*>::const_iterator it; for (it = inherentSkillMap.begin(); it != inherentSkillMap.end(); ++it) { - it->second->StartCooling(GetCoolTime(pCmd->cooldown_index), GetCoolTime(pCmd->cooldown_index)); + it.second.StartCooling(GetCoolTime(pCmd.cooldown_index), GetCoolTime(pCmd.cooldown_index)); }*/ } } @@ -648,7 +648,7 @@ namespace BrewMonster } /* else if (pSkill = CECComboSkillState::Instance().GetInherentSkillByID(idSkill)) { - pSkill->StartCooling(pCmd->cooldown_time, pCmd->cooldown_time); + pSkill.StartCooling(pCmd.cooldown_time, pCmd.cooldown_time); }*/ else if (GetEquipSkillByID(idSkill) == null) { @@ -943,7 +943,7 @@ namespace BrewMonster // Print a notify message // 打印提示消息 - // g_pGame->GetGameRun()->AddFixedMessage(FIXMSG_SKILLINTERRUPT); + // g_pGame.GetGameRun().AddFixedMessage(FIXMSG_SKILLINTERRUPT); Debug.Log("Skill interrupted!"); //AP_ActionEvent(AP_EVENT_STOPSKILL); @@ -1210,7 +1210,7 @@ namespace BrewMonster // Continue combo skill // 继续连击技能 // if (CECAutoPolicy::GetInstance().IsAutoPolicyEnabled()) - // g_pGame->GetGameRun()->PostMessage(MSG_HST_CONTINUECOMBOSKILL, MAN_PLAYER, 0, 0, m_pComboSkill->GetGroupIndex()); + // g_pGame.GetGameRun().PostMessage(MSG_HST_CONTINUECOMBOSKILL, MAN_PLAYER, 0, 0, m_pComboSkill.GetGroupIndex()); // else m_pComboSkill.Continue(false); } @@ -3310,21 +3310,21 @@ namespace BrewMonster } /* else if (pSkill.GetType() == CECSkill::TYPE_BLESSPET) { - CECPet* pPet = g_pGame->GetGameRun()->GetWorld()->GetNPCMan()->GetPetByID(idSelTarget); - if (!pPet || pPet->GetMasterID() == GetCharacterID()) + CECPet* pPet = g_pGame.GetGameRun().GetWorld().GetNPCMan().GetPetByID(idSelTarget); + if (!pPet || pPet.GetMasterID() == GetCharacterID()) { // Spell skill on host's pet - CECPetData* pPetData = m_pPetCorral->GetActivePet(); + CECPetData* pPetData = m_pPetCorral.GetActivePet(); if (!pPetData || - pPetData->GetClass() != GP_PET_CLASS_COMBAT && - pPetData->GetClass() != GP_PET_CLASS_SUMMON && - pPetData->GetClass() != GP_PET_CLASS_EVOLUTION) + pPetData.GetClass() != GP_PET_CLASS_COMBAT && + pPetData.GetClass() != GP_PET_CLASS_SUMMON && + pPetData.GetClass() != GP_PET_CLASS_EVOLUTION) return false; - idCastTarget = m_pPetCorral->GetActivePetNPCID(); + idCastTarget = m_pPetCorral.GetActivePetNPCID(); } // Only fighting pet can be blessed. - if (pPet && !pPet->CanBeAttacked()) + if (pPet && !pPet.CanBeAttacked()) return false; }*/ else @@ -3334,7 +3334,7 @@ namespace BrewMonster } // iTargetType == 4 means target must be pet. The problem is that pet will - // disappear from world after it died, so GetWorld()->GetObject() will return + // disappear from world after it died, so GetWorld().GetObject() will return // NULL when host spells revive-pet skill on his dead pet. So, the target // type of revive-pet skill should be 0 if (iTargetType != 0) @@ -3396,7 +3396,7 @@ namespace BrewMonster bool bTraceOK = false; bool bUseAutoPF = false; /* CECPlayerWrapper pWrapper = CECAutoPolicy::GetInstance().GetPlayerWrapper(); - if (CECAutoPolicy::GetInstance().IsAutoPolicyEnabled() && pWrapper->GetAttackError() >= 2) + if (CECAutoPolicy::GetInstance().IsAutoPolicyEnabled() && pWrapper.GetAttackError() >= 2) bUseAutoPF = true;*/ if (idCastTarget == 0) @@ -4276,12 +4276,12 @@ namespace BrewMonster case ActionCanDo.CANDO_FLY: - if (IsDead() || IsRooting() /*|| IsSitting() || IsTrading() || IsReviving() || + if (IsDead() || IsRooting() || IsSitting() || IsTrading() || IsReviving() || IsUsingTrashBox() || IsTalkingWithNPC() || IsChangingFace() || GetBoothState() != 0 || - IsFlashMoving() */ || - m_pWorkMan.HasWorkRunningOnPriority(CECHPWorkMan.Work_priority.PRIORITY_2) /*|| - m_bHangerOn || IsOperatingPet() || IsRebuildingPet() || - IsUsingItem() || IsRidingOnPet() || GetShapeType() == PLAYERMODEL_DUMMYTYPE2 || IsPassiveMove() || + //IsFlashMoving() || + m_pWorkMan.HasWorkRunningOnPriority(CECHPWorkMan.Work_priority.PRIORITY_2) || + m_bHangerOn || /*IsOperatingPet() || IsRebuildingPet() ||*/ + IsUsingItem() || /*IsRidingOnPet() || GetShapeType() == PLAYERMODEL_DUMMYTYPE2 ||*/ IsPassiveMove() /*|| m_playerLimits.test(PLAYER_LIMIT_NOFLY) || m_BattleInfo.IsChariotWar()*/) bRet = false; @@ -4586,8 +4586,8 @@ namespace BrewMonster { if (IsDead()) { - /* CECGameUIMan pGameUI = g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); - pGameUI->PopupReviveDialog(true);*/ + /* CECGameUIMan pGameUI = g_pGame.GetGameRun().GetUIManager().GetInGameUIMan(); + pGameUI.PopupReviveDialog(true);*/ PopupManager.Instance.OnPlayerDied(); } m_bEnterGame = true; @@ -5654,9 +5654,9 @@ namespace BrewMonster // if( m_iBuddyId ) // { - // CECPlayer pBuddy = m_pPlayerMan->GetPlayer(m_iBuddyId); + // CECPlayer pBuddy = m_pPlayerMan.GetPlayer(m_iBuddyId); // if (pBuddy) - // pBuddy->DoEmote(pCmd->emotion); + // pBuddy.DoEmote(pCmd.emotion); // } GetTaskInterface().SetEmotion(pCmd.emotion); @@ -5983,15 +5983,15 @@ namespace BrewMonster { cmd_player_gather_start pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); - EC_ManMatter pMatterMan = EC_ManMessageMono.Instance.GetECManMatter;//g_pGame->GetGameRun()->GetWorld()->GetMatterMan(); + EC_ManMatter pMatterMan = EC_ManMessageMono.Instance.GetECManMatter;//g_pGame.GetGameRun().GetWorld().GetMatterMan(); CECMatter pMatter = pMatterMan.GetMatter(pCmd.mid); - // if (pMatter && pMatter->IsMonsterSpiritMine()) { - // CECHPWorkUse* pWork = (CECHPWorkUse*)m_pWorkMan->CreateWork(CECHPWork::WORK_USEITEM); + // if (pMatter && pMatter.IsMonsterSpiritMine()) { + // CECHPWorkUse* pWork = (CECHPWorkUse*)m_pWorkMan.CreateWork(CECHPWork::WORK_USEITEM); // if (pWork) { - // pWork->SetParams(pCmd->mid, pCmd->use_time * 1000, pCmd->mid, true); - // m_pWorkMan->StartWork_p1(pWork); + // pWork.SetParams(pCmd.mid, pCmd.use_time * 1000, pCmd.mid, true); + // m_pWorkMan.StartWork_p1(pWork); // } - // StartMonsterSpiritConnectGfx(pCmd->mid, pMatter->GetPos()); + // StartMonsterSpiritConnectGfx(pCmd.mid, pMatter.GetPos()); // } else { EC_HPWorkPick pWork = (EC_HPWorkPick)m_pWorkMan.CreateWork(Host_work_ID.WORK_PICKUP); if (pWork != null) @@ -6028,7 +6028,7 @@ namespace BrewMonster else if (cmd == CommandID.MINE_GATHERED) { cmd_mine_gathered pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); - // ASSERT(pCmd && pCmd->player_id == m_PlayerInfo.cid); + // ASSERT(pCmd && pCmd.player_id == m_PlayerInfo.cid); elementdataman pDataMan = EC_Game.GetElementDataMan(); DATA_TYPE DataType = pDataMan.get_data_type((uint)pCmd.item_type, ID_SPACE.ID_SPACE_ESSENCE); if (DataType == DATA_TYPE.DT_MONSTER_SPIRIT_ESSENCE) @@ -6305,5 +6305,42 @@ namespace BrewMonster } return false; } + + // Start / Stop flying + public bool CmdFly(bool bForceFly) + { + //if (m_pActionSwitcher) + // m_pActionSwitcher.PostMessge(CECActionSwitcherBase::MSG_FLY); + + // first of all see if we need to cancel sitdown work. + + + if (!CanDo(ActionCanDo.CANDO_FLY)) + return false; + + EC_IvtrItem pItem = EquipInventory.GetItem(InventoryConst.EQUIPIVTR_FLYSWORD); + if (pItem == null) + return false; + + if (((EC_IvtrEquip)pItem).IsDestroying()) + return false; + + if (!IsFlying()) + { + // TODO: Maybe we should let server tell us whether we can fly or not + bool bCanFly = true; + + if (m_iMoveEnv == (int)MoveEnvironment.MOVEENV_AIR) + bCanFly = false; + else if (m_iMoveEnv == (int)MoveEnvironment.MOVEENV_WATER && !CanTakeOffWater()) + bCanFly = false; + + if (!bCanFly) + return false; + } + + UnityGameSession.c2s_CmdUseItem(InventoryConst.IVTRTYPE_EQUIPPACK, InventoryConst.EQUIPIVTR_FLYSWORD, pItem.GetTemplateID(), 1); + return true; + } } }