KPlayer.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:187k
- }
- else
- {
- sDecision.m_btDecision = 3;
- }
- if (g_pClient)
- g_pClient->SendPackToServer(&sDecision, sizeof(TRADE_DECISION_COMMAND));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到服务器通知有人申请加入队伍
- //-------------------------------------------------------------------------
- void KPlayer::s2cApplyAddTeam(BYTE* pProtocol)
- {
- // 状态检查 (还需要检查 npc 的队伍开放状态 not end)
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- {
- ApplySelfTeamInfo();
- return;
- }
-
- // 寻找 npc
- PLAYER_APPLY_ADD_TEAM *pAddTeam = (PLAYER_APPLY_ADD_TEAM*)pProtocol;
- int nNpcNo = NpcSet.SearchID(pAddTeam->m_dwTarNpcID);
- if (nNpcNo == 0)
- return;
-
- int i, nFreeListNo;
- // 如果已经存在,更新
- for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
- {
- if (m_cTeam.m_sApplyList[i].m_dwNpcID == pAddTeam->m_dwTarNpcID)
- {
- m_cTeam.m_sApplyList[i].m_nLevel = Npc[nNpcNo].m_Level;
- m_cTeam.m_sApplyList[i].m_dwTimer = MAX_APPLY_TEAM_TIME;
- strcpy(m_cTeam.m_sApplyList[i].m_szName, Npc[nNpcNo].Name);
- m_cTeam.UpdateInterface();
- return;
- }
- }
- // 寻找申请人list空位
- for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
- {
- if (m_cTeam.m_sApplyList[i].m_dwNpcID == 0)
- {
- nFreeListNo = i;
- break;
- }
- }
- if (i >= MAX_TEAM_APPLY_LIST) // 没找到申请人空位
- return;
-
- m_cTeam.m_sApplyList[nFreeListNo].m_dwNpcID = pAddTeam->m_dwTarNpcID;
- m_cTeam.m_sApplyList[nFreeListNo].m_nLevel = Npc[nNpcNo].m_Level;
- m_cTeam.m_sApplyList[nFreeListNo].m_dwTimer = MAX_APPLY_TEAM_TIME;
- strcpy(m_cTeam.m_sApplyList[nFreeListNo].m_szName, Npc[nNpcNo].Name);
-
- m_cTeam.UpdateInterface();
-
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TEAM_APPLY_ADD, Npc[nNpcNo].Name);
- sMsg.eType = SMT_TEAM;
- sMsg.byConfirmType = SMCT_UI_TEAM_APPLY;
- sMsg.byPriority = 3;
- sMsg.byParamSize = sizeof(KUiPlayerItem);
- KUiPlayerItem player;
- strcpy(player.Name, Npc[nNpcNo].Name);
- player.nIndex = 0;
- player.uId = pAddTeam->m_dwTarNpcID;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&player);
-
- return;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:加入门派
- //-------------------------------------------------------------------------
- BOOL KPlayer::AddFaction(char *lpszFactionName)
- {
- if ( !m_cFaction.AddFaction(Npc[m_nIndex].m_Series, lpszFactionName) )
- return FALSE;
-
- // 改变阵营
- Npc[m_nIndex].SetCamp(m_cFaction.GetGurFactionCamp());
-
- // 给客户端发消息
- SendFactionData();
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:加入门派
- //-------------------------------------------------------------------------
- BOOL KPlayer::AddFaction(int nFactionID)
- {
- if ( !m_cFaction.AddFaction(Npc[m_nIndex].m_Series, nFactionID) )
- return FALSE;
-
- // 改变阵营
- Npc[m_nIndex].SetCamp(m_cFaction.GetGurFactionCamp());
-
- // 给客户端发消息
- SendFactionData();
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:离开门派
- //-------------------------------------------------------------------------
- BOOL KPlayer::LeaveCurFaction()
- {
- m_cFaction.LeaveFaction();
-
- // 改变阵营
- Npc[m_nIndex].SetCamp(camp_free);
-
- // 给客户端发消息
- PLAYER_LEAVE_FACTION sLeave;
- sLeave.ProtocolType = s2c_playerleavefaction;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeave, sizeof(PLAYER_LEAVE_FACTION));
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:开放当前门派某个等级的技能
- //-------------------------------------------------------------------------
- BOOL KPlayer::CurFactionOpenSkill(int nLevel)
- {
- if ( !m_cFaction.OpenCurSkillLevel(nLevel, &Npc[m_nIndex].m_SkillList) )
- return FALSE;
-
- PLAYER_FACTION_SKILL_LEVEL sLevel;
- sLevel.ProtocolType = s2c_playerfactionskilllevel;
- sLevel.m_btCurFactionID = m_cFaction.m_nCurFaction;
- sLevel.m_btLevel = nLevel;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_FACTION_SKILL_LEVEL));
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:清空任务临时变量
- //-------------------------------------------------------------------------
- void KPlayer::TaskClearTempVal()
- {
- this->m_cTask.ClearTempVar();
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:得到任务完成情况
- //-------------------------------------------------------------------------
- int KPlayer::TaskGetSaveVal(int nNo)
- {
- return this->m_cTask.GetSaveVal(nNo);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定任务完成情况
- //-------------------------------------------------------------------------
- void KPlayer::TaskSetSaveVal(int nNo, BOOL bFlag)
- {
- this->m_cTask.SetSaveVal(nNo, bFlag);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:得到任务临时过程控制变量值
- //-------------------------------------------------------------------------
- int KPlayer::TaskGetClearVal(int nNo)
- {
- return this->m_cTask.GetClearVal(nNo);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定任务临时过程控制变量值
- //-------------------------------------------------------------------------
- void KPlayer::TaskSetClearVal(int nNo, int nVal)
- {
- this->m_cTask.SetClearVal(nNo, nVal);
- }
- #endif
- #ifndef _SERVER
- void KPlayer::SetDefaultImmedSkill()
- {
- //获取玩家左右键技能为默认物理技能
- int nDetailType = Player[CLIENT_PLAYER_INDEX].m_ItemList.GetWeaponType();
- int nParticularType = Player[CLIENT_PLAYER_INDEX].m_ItemList.GetWeaponParticular();
-
- //近身武器
- if (nDetailType == 0)
- {
- Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nMeleeWeaponSkill[nParticularType]);
- Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nMeleeWeaponSkill[nParticularType]);
- }//远程武器
- else if (nDetailType == 1)
- {
- Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nRangeWeaponSkill[nParticularType]);
- Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nRangeWeaponSkill[nParticularType]);
- }//空手
- else if (nDetailType == -1)
- {
- Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nHandSkill);
- Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nHandSkill);
- }
- }
- void KPlayer::SetLeftSkill(int nSkillID)
- {
- if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.GetCurrentLevel(nSkillID) <= 0) return;
- m_nLeftSkillID = nSkillID;
-
- KUiGameObject Info;
- Info.uGenre = CGOG_SKILL_SHORTCUT;
- Info.uId = m_nLeftSkillID;
- CoreDataChanged(GDCNI_PLAYER_IMMED_ITEMSKILL, (unsigned int)&Info, -1);
- }
- void KPlayer::SetRightSkill(int nSkillID)
- {
- if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.GetCurrentLevel(nSkillID) <= 0) return;
- m_nRightSkillID = nSkillID;
- // 检查是否是光环技能
- ISkill * pOrdinSkill = g_SkillManager.GetSkill(nSkillID, 1);
- if (!pOrdinSkill)
- return;
-
- if (pOrdinSkill->IsAura())
- {
- Npc[m_nIndex].SetAuraSkill(nSkillID);
- }
- else
- {
- Npc[m_nIndex].SetAuraSkill(0);
- }
-
- KUiGameObject Info;
- Info.uGenre = CGOG_SKILL_SHORTCUT;
- Info.uId = m_nRightSkillID;
- CoreDataChanged(GDCNI_PLAYER_IMMED_ITEMSKILL, (unsigned int)&Info, -2);
- }
- void KPlayer::UpdateWeaponSkill()
- {
- if (m_nLeftSkillID > 0)
- {
- ISkill * pISkill = g_SkillManager.GetSkill(m_nLeftSkillID, 1);
- if (!pISkill)
- return;
-
- if (pISkill->IsPhysical())
- {
- SetLeftSkill(Npc[m_nIndex].GetCurActiveWeaponSkill());
- }
-
- }
- if (m_nRightSkillID > 0)
- {
- ISkill * pISkill = (KSkill *) g_SkillManager.GetSkill(m_nRightSkillID, 1);
- if (!pISkill)
- return;
-
- if (pISkill->IsPhysical())
- {
- SetRightSkill(Npc[m_nIndex].GetCurActiveWeaponSkill());
- }
- }
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定当前聊天频道
- //-------------------------------------------------------------------------
- void KPlayer::SetChatCurChannel(int nChannelNo)
- {
- m_cChat.SetCurChannel(nChannelNo);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:邀请加入队伍
- //-------------------------------------------------------------------------
- void KPlayer::TeamInviteAdd(DWORD dwNpcID)
- {
- m_cTeam.InviteAdd(dwNpcID);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端发来的聊天语句
- //-------------------------------------------------------------------------
- void KPlayer::ServerSendChat(BYTE* pProtocol)
- {
- m_cChat.ServerSendChat(m_nPlayerIndex, pProtocol);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端要求增加基本属性点(0=Strength 1=Dexterity 2=Vitality 3=Engergy)
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseAttribute(BYTE* pProtocol)
- {
- PLAYER_ADD_BASE_ATTRIBUTE_COMMAND *pAdd = (PLAYER_ADD_BASE_ATTRIBUTE_COMMAND*)pProtocol;
- switch (pAdd->m_btAttribute)
- {
- case ATTRIBUTE_STRENGTH:
- AddBaseStrength(pAdd->m_nAddNo);
- break;
- case ATTRIBUTE_DEXTERITY:
- AddBaseDexterity(pAdd->m_nAddNo);
- break;
- case ATTRIBUTE_VITALITY:
- AddBaseVitality(pAdd->m_nAddNo);
- break;
- case ATTRIBUTE_ENGERGY:
- AddBaseEngergy(pAdd->m_nAddNo);
- break;
- }
- }
- #endif
- #define MAX_ORDINSKILL_LEVEL_ALWAYS 20//不包括其它情况对技能等级的变动之外的,一般最大技能等级
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端要求增加某个技能的点数
- //-------------------------------------------------------------------------
- void KPlayer::AddSkillPoint(BYTE* pProtocol)
- {
- PLAYER_ADD_SKILL_POINT_COMMAND *pAdd = (PLAYER_ADD_SKILL_POINT_COMMAND*)pProtocol;
-
- int nSkillIndex, nSkillLevel;
-
- nSkillIndex = Npc[m_nIndex].m_SkillList.FindSame(pAdd->m_nSkillID);
- if (nSkillIndex == 0)
- return;
- nSkillLevel = Npc[m_nIndex].m_SkillList.GetSkillIdxLevel(nSkillIndex);
-
-
- if (m_nSkillPoint >= pAdd->m_nAddPoint && nSkillIndex )//&& nSkillLevel + pAdd->m_nAddPoint <= MAX_SKILLLEVEL
- {
- ISkill * pSkill = NULL;
- if (nSkillLevel == 0)
- {
- pSkill = g_SkillManager.GetSkill(pAdd->m_nSkillID, 1);
- }
- else
- {
- pSkill = g_SkillManager.GetSkill(pAdd->m_nSkillID, nSkillLevel);
- }
-
- if (pSkill)
- {
- //有对应的技能升级脚本,优先执行脚本
- if (pSkill->GetSkillLevelUpScriptId())
- {
- ExecuteScript(pSkill->GetSkillLevelUpScriptId(), "main", pAdd->m_nAddPoint);
- nSkillLevel = Npc[m_nIndex].m_SkillList.GetSkillIdxLevel(nSkillIndex);
- }
- else
- {
- /*
- 技能升级的常规
- 1。所有能够加点的技能,最高只能加到20级。
- 2。假设一个玩家的等级是x,一个技能的基本学习等级是y,那么他能够学习这个技能的最高等级是x-y。
- 3。使用技能需要加入一些情况的判断,第一,是否是骑马状态;第二,他装备的武器的详细类别是否为指定数值,-1表示没有需求。
- */
- switch(pSkill->GetSkillStyle())
- {
- case SKILL_SS_Missles: // 子弹类 本技能用于发送子弹类
- case SKILL_SS_Melee:
- case SKILL_SS_InitiativeNpcState: // 主动类 本技能用于改变当前Npc的主动状态
- case SKILL_SS_PassivityNpcState: // 被动类 本技能用于改变Npc的被动状态
- {
- int nWantToBeLevel = nSkillLevel + pAdd->m_nAddPoint;
- //Limit2
- if (nWantToBeLevel <= g_SkillManager.GetSkillMaxLevel(pAdd->m_nSkillID) && nWantToBeLevel <= Npc[m_nIndex].m_Level - ((KSkill*)pSkill)->GetSkillReqLevel() + 1)
- {
- if ( !Npc[m_nIndex].m_SkillList.IncreaseLevel(nSkillIndex, pAdd->m_nAddPoint) )
- return;
- m_nSkillPoint -= pAdd->m_nAddPoint;
- nSkillLevel += pAdd->m_nAddPoint;
- }
- else
- {
- if (nWantToBeLevel >= g_SkillManager.GetSkillMaxLevel(pAdd->m_nSkillID))
- {
- char szMsg[100];
- sprintf(szMsg, "您的%s技能等级已经达到极限,不能再升级了。", pSkill->GetSkillName());
- KPlayerChat::SendSystemInfo(1, m_nPlayerIndex, "技能升级消息", (char *) szMsg, strlen(szMsg) );
- }
- else
- {
- char szMsg[100];
- sprintf(szMsg, "您的战斗技能必须达到%d级才能升级%s技能。", ((KSkill *)pSkill)->GetSkillReqLevel() -1 + pAdd->m_nAddPoint + nSkillLevel, ((KSkill*)pSkill)->GetSkillName());
- KPlayerChat::SendSystemInfo(1, m_nPlayerIndex, "技能升级消息", (char *) szMsg, strlen(szMsg) );
- }
-
- }
- }
- break;
-
- case SKILL_SS_Thief:
- {
- return;
- }break;
-
- }
-
- }
-
- // 把当前此技能的点数和剩余技能点发给客户端
- PLAYER_SKILL_LEVEL_SYNC sSkill;
- sSkill.ProtocolType = s2c_playerskilllevel;
- sSkill.m_nSkillID = pAdd->m_nSkillID;
- sSkill.m_nSkillLevel = nSkillLevel;
- sSkill.m_nLeavePoint = m_nSkillPoint;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSkill, sizeof(PLAYER_SKILL_LEVEL_SYNC));
- }
- }
-
-
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:服务器端拣物品
- //-------------------------------------------------------------------------
- BOOL KPlayer::ServerPickUpItem(BYTE* pProtocol)
- {
- PLAYER_PICKUP_ITEM_COMMAND *pPickUp = (PLAYER_PICKUP_ITEM_COMMAND*)pProtocol;
-
- int nObjIndex, nNpcX, nNpcY, nObjX, nObjY;
- nObjIndex = ObjSet.FindID(pPickUp->m_nObjID);
- if (nObjIndex == 0)
- return FALSE;
-
- if (Object[nObjIndex].m_nBelong != -1)
- {
- if (!m_cTeam.m_nFlag)
- {
- if (Object[nObjIndex].m_nBelong != m_nPlayerIndex)
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
- sMsg.m_wMsgID = enumMSG_ID_MONEY_CANNOT_PICKUP;
- else
- sMsg.m_wMsgID = enumMSG_ID_OBJ_CANNOT_PICKUP;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
- }
- else
- {
- if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
- {
- if (Object[nObjIndex].m_nBelong != m_nPlayerIndex &&
- !g_Team[m_cTeam.m_nID].CheckIn(Object[nObjIndex].m_nBelong))
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_MONEY_CANNOT_PICKUP;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
- }
- else if (Object[nObjIndex].m_nKind == Obj_Kind_Item)
- {
- if (Object[nObjIndex].m_nItemDataID <= 0 || Object[nObjIndex].m_nItemDataID >= MAX_ITEM)
- {
- _ASSERT(0);
- return FALSE;
- }
- if ((Item[Object[nObjIndex].m_nItemDataID].GetGenre() == item_task && Object[nObjIndex].m_nBelong != m_nPlayerIndex) ||
- !g_Team[m_cTeam.m_nID].CheckIn(Object[nObjIndex].m_nBelong))
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_OBJ_CANNOT_PICKUP;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
- }
- // 判断距离
- if (Object[nObjIndex].m_nSubWorldID != Npc[m_nIndex].m_SubWorldIndex)
- return FALSE;
- SubWorld[Object[nObjIndex].m_nSubWorldID].Map2Mps(
- Object[nObjIndex].m_nRegionIdx,
- Object[nObjIndex].m_nMapX,
- Object[nObjIndex].m_nMapY,
- Object[nObjIndex].m_nOffX,
- Object[nObjIndex].m_nOffY,
- &nObjX,
- &nObjY);
- SubWorld[Npc[m_nIndex].m_SubWorldIndex].Map2Mps(
- Npc[m_nIndex].m_RegionIndex,
- Npc[m_nIndex].m_MapX,
- Npc[m_nIndex].m_MapY,
- Npc[m_nIndex].m_OffX,
- Npc[m_nIndex].m_OffY,
- &nNpcX,
- &nNpcY);
- if ( PLAYER_PICKUP_SERVER_DISTANCE < (nNpcX - nObjX) * (nNpcX - nObjX) + (nNpcY - nObjY) * (nNpcY - nObjY))
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_OBJ_TOO_FAR;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
-
- switch (Object[nObjIndex].m_nKind)
- {
- case Obj_Kind_Item: // 掉在地上的装备
- {
- int nItemIdx = m_ItemList.Add(Object[nObjIndex].m_nItemDataID, pPickUp->m_btPosType, pPickUp->m_btPosX, pPickUp->m_btPosY);
- if (nItemIdx <= 0 || nItemIdx >= MAX_PLAYER_ITEM)
- return FALSE;
- if (Object[nObjIndex].m_nItemDataID <= 0 || Object[nObjIndex].m_nItemDataID >= MAX_ITEM)
- return FALSE;
- // 给客户端发送获得装备的消息
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_GET_ITEM;
- sMsg.m_lpBuf = (LPVOID)Item[Object[nObjIndex].m_nItemDataID].GetID();
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
-
- // 去掉Object[nObjIndex]与道具的关联。避免ItemSet的Remove被Object的Remove调用
- Object[nObjIndex].m_nItemDataID = 0;
- Object[nObjIndex].m_nItemWidth = 0;
- Object[nObjIndex].m_nItemHeight = 0;
- Object[nObjIndex].Remove(FALSE);
-
- }
- break;
- case Obj_Kind_Money: // 掉在地上的钱
- if ( !Earn(Object[nObjIndex].m_nMoneyNum) )
- return FALSE;
- Object[nObjIndex].SyncRemove(TRUE);
- if (Object[nObjIndex].m_nRegionIdx >= 0)
- SubWorld[Object[nObjIndex].m_nSubWorldID].m_Region[Object[nObjIndex].m_nRegionIdx].RemoveObj(nObjIndex);
- ObjSet.Remove(nObjIndex);
- break;
- }
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端要求使用某个物品(鼠标右键点击)
- //-------------------------------------------------------------------------
- void KPlayer::EatItem(BYTE* pProtocol)
- {
- PLAYER_EAT_ITEM_COMMAND *pEat = (PLAYER_EAT_ITEM_COMMAND*)pProtocol;
-
- m_ItemList.EatMecidine(pEat->m_btPlace, pEat->m_btX, pEat->m_btY);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端要求使用某个物品(鼠标右键点击)
- //-------------------------------------------------------------------------
- //void KPlayer::UseItem(BYTE* pProtocol)
- //{
- // PLAYER_USE_ITEM_COMMAND *pItem = (PLAYER_USE_ITEM_COMMAND*)pProtocol;
- //}
- #endif
- #ifdef _SERVER
- void KPlayer::ServerMoveItem(BYTE* pProtocol)
- {
- PLAYER_MOVE_ITEM_COMMAND *pMove = (PLAYER_MOVE_ITEM_COMMAND*)pProtocol;
- ItemPos DownPos, UpPos;
-
- DownPos.nPlace = pMove->m_btDownPos;
- DownPos.nX = pMove->m_btDownX;
- DownPos.nY = pMove->m_btDownY;
- UpPos.nPlace = pMove->m_btUpPos;
- UpPos.nX = pMove->m_btUpX;
- UpPos.nY = pMove->m_btUpY;
-
- //EXCHANGE_ITEM_RESPONE eir;
- //eir.ProtocolType = s2c_exchangerespone;
-
- if (this->CheckTrading() && DownPos.nPlace == pos_traderoom)
- {
- if (this->m_cTrade.m_nTradeLock)
- return;
- }
-
- m_ItemList.ExchangeItem(&DownPos, &UpPos);
-
- BYTE byFinished = s2c_itemexchangefinish;
- if (g_pServer)
- g_pServer->PackDataToClient(m_nNetConnectIdx, &byFinished, sizeof(BYTE));
- }
- #endif
- #ifdef _SERVER
- void KPlayer::ServerThrowAwayItem(BYTE* pProtocol)
- {
- PLAYER_THROW_AWAY_ITEM_COMMAND *pThrow = (PLAYER_THROW_AWAY_ITEM_COMMAND*)pProtocol;
- KMapPos sMapPos;
-
- if ( !this->m_ItemList.Hand() )
- return;
-
- int nItemIdx = m_ItemList.m_Hand;
- GetAboutPos(&sMapPos);
- if (m_ItemList.Remove(nItemIdx))
- {
- int nObj;
- KObjItemInfo sInfo;
- sInfo.m_nItemID = nItemIdx;
- sInfo.m_nItemWidth = Item[nItemIdx].GetWidth();
- sInfo.m_nItemHeight = Item[nItemIdx].GetHeight();
- sInfo.m_nMoneyNum = 0;
- strcpy(sInfo.m_szName, Item[nItemIdx].m_CommonAttrib.szItemName);
- sInfo.m_nColorID = 0;
- sInfo.m_nMovieFlag = 1;
- sInfo.m_nSoundFlag = 1;
-
- nObj = ObjSet.Add(Item[nItemIdx].GetObjIdx(), sMapPos, sInfo);
- if (nObj >= 0)
- {
- if (Item[nItemIdx].GetGenre() == item_task)
- {
- Object[nObj].SetEntireBelong(this->m_nPlayerIndex);
- }
- else
- {
- Object[nObj].SetItemBelong(-1);
- }
- }
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端消息设定聊天订阅频道
- //-------------------------------------------------------------------------
- void KPlayer::ChatSetTakeChannel(BYTE* pProtocol)
- {
- CHAT_SET_CHANNEL_COMMAND *pChannel = (CHAT_SET_CHANNEL_COMMAND*)pProtocol;
- this->m_cChat.SetTakeChannel(pChannel->m_dwTakeChannel);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求转发聊天添加好友信息
- //-------------------------------------------------------------------------
- void KPlayer::ChatTransmitApplyAddFriend(BYTE* pProtocol)
- {
- CHAT_APPLY_ADD_FRIEND_COMMAND *pAdd = (CHAT_APPLY_ADD_FRIEND_COMMAND*)pProtocol;
- int nPlayerIdx = FindAroundPlayer(pAdd->m_dwTargetNpcID);
- if (nPlayerIdx < 0)
- return;
-
- m_cChat.m_nAddFriendList[m_cChat.m_nListPos++] = nPlayerIdx;
- m_cChat.m_nListPos %= CHAT_APPLY_ADD_FRIEND_LIST;
-
- CHAT_APPLY_ADD_FRIEND_SYNC sAdd;
- sAdd.ProtocolType = s2c_chatapplyaddfriend;
- sAdd.m_nSrcPlayerIdx = m_nPlayerIndex;
- strcpy(sAdd.m_szSourceName, Npc[m_nIndex].Name);
- memset(sAdd.m_szInfo, 0, sizeof(sAdd.m_szInfo));
- memcpy(sAdd.m_szInfo, pAdd->m_szInfo, pAdd->m_wLength + 1 + sizeof(pAdd->m_szInfo) - sizeof(CHAT_APPLY_ADD_FRIEND_COMMAND));
- g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sAdd, sizeof(CHAT_APPLY_ADD_FRIEND_SYNC));
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端消息添加聊天好友
- //-------------------------------------------------------------------------
- BOOL KPlayer::ChatAddFriend(BYTE* pProtocol)
- {
- CHAT_ADD_FRIEND_COMMAND *pAdd = (CHAT_ADD_FRIEND_COMMAND*)pProtocol;
-
- if (pAdd->m_nTargetPlayerIdx < 0 || pAdd->m_nTargetPlayerIdx >= MAX_PLAYER)
- goto AddFalse;
- if ( !Player[pAdd->m_nTargetPlayerIdx].m_nIndex )
- goto AddFalse;
- int i;
- for (i = 0; i < CHAT_APPLY_ADD_FRIEND_LIST; i++)
- {
- if (m_nPlayerIndex == Player[pAdd->m_nTargetPlayerIdx].m_cChat.m_nAddFriendList[i])
- break;
- }
- if (i >= CHAT_APPLY_ADD_FRIEND_LIST)
- goto AddFalse;
-
- m_cChat.AddFriendData(m_nPlayerIndex, pAdd->m_nTargetPlayerIdx);
- Player[pAdd->m_nTargetPlayerIdx].m_cChat.AddFriendData(pAdd->m_nTargetPlayerIdx, m_nPlayerIndex);
-
- return TRUE;
-
- AddFalse:
- CHAT_ADD_FRIEND_FAIL_SYNC sFail;
- sFail.ProtocolType = s2c_chataddfriendfail;
- sFail.m_nTargetPlayerIdx = pAdd->m_nTargetPlayerIdx;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sFail, sizeof(CHAT_ADD_FRIEND_FAIL_SYNC));
-
- return FALSE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端消息拒绝添加聊天好友
- //-------------------------------------------------------------------------
- void KPlayer::ChatRefuseFriend(BYTE* pProtocol)
- {
- CHAT_REFUSE_FRIEND_COMMAND *pRefuse = (CHAT_REFUSE_FRIEND_COMMAND*)pProtocol;
-
- if (pRefuse->m_nTargetPlayerIdx < 0 || pRefuse->m_nTargetPlayerIdx >= MAX_PLAYER)
- return;
- if (Player[pRefuse->m_nTargetPlayerIdx].m_nIndex == 0)
- return;
- for (int i = 0; i < CHAT_APPLY_ADD_FRIEND_LIST; i++)
- {
- if (m_nPlayerIndex == Player[pRefuse->m_nTargetPlayerIdx].m_cChat.m_nAddFriendList[i])
- {
- CHAT_REFUSE_FRIEND_SYNC sRefuse;
- sRefuse.ProtocolType = s2c_chatrefusefriend;
- g_StrCpy(sRefuse.m_szName, Npc[m_nIndex].Name);
- sRefuse.m_wLength = sizeof(CHAT_REFUSE_FRIEND_SYNC) - 1 - sizeof(sRefuse.m_szName) + strlen(sRefuse.m_szName);
-
- g_pServer->PackDataToClient(Player[pRefuse->m_nTargetPlayerIdx].m_nNetConnectIdx, (BYTE*)&sRefuse, sRefuse.m_wLength + 1);
- return;
- }
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家登录时收到客户端请求重新发送所有聊天好友数据(带名字)
- //-------------------------------------------------------------------------
- void KPlayer::ChatResendAllFriend(BYTE* pProtocol)
- {
- if ( m_cChat.m_nSyncState != 1)
- return;
- m_cChat.m_nSyncState = 2;
- m_cChat.m_pStateSendPos = (CChatFriend*)m_cChat.m_cFriendTeam[0].m_cEveryOne.GetHead();
- if ( !m_cChat.m_pStateSendPos )
- m_cChat.m_nSyncState = 0;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家登录时收到客户端请求发送某个聊天好友数据(带名字)
- //-------------------------------------------------------------------------
- void KPlayer::ChatSendOneFriendData(BYTE* pProtocol)
- {
- CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND *pApply = (CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND*)pProtocol;
-
- m_cChat.ResendOneFriendData(pApply->m_dwID, m_nPlayerIndex);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端申请删除某个聊天好友
- //-------------------------------------------------------------------------
- void KPlayer::ChatDeleteFriend(BYTE* pProtocol)
- {
- CHAT_DELETE_FRIEND_COMMAND *pDelete = (CHAT_DELETE_FRIEND_COMMAND*)pProtocol;
-
- m_cChat.DeleteFriend(pDelete->m_dwID, m_dwID);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端申请再次删除某个聊天好友
- //-------------------------------------------------------------------------
- void KPlayer::ChatRedeleteFriend(BYTE* pProtocol)
- {
- CHAT_REDELETE_FRIEND_COMMAND *pDelete = (CHAT_REDELETE_FRIEND_COMMAND*)pProtocol;
-
- this->m_cChat.RedeleteFriend(pDelete->m_dwID, m_nPlayerIndex);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端申请进入待交易状态
- //-------------------------------------------------------------------------
- void KPlayer::TradeApplyOpen(BYTE* pProtocol)
- {
- if ( CheckTrading() )
- return;
- TRADE_APPLY_OPEN_COMMAND *pApply = (TRADE_APPLY_OPEN_COMMAND*)pProtocol;
- char szSentence[MAX_SENTENCE_LENGTH];
- int nLength = pApply->m_wLength - (sizeof(TRADE_APPLY_OPEN_COMMAND) - 1 - sizeof(pApply->m_szSentence));
- if (nLength >= MAX_SENTENCE_LENGTH)
- nLength = MAX_SENTENCE_LENGTH - 1;
- memset(szSentence, 0, sizeof(szSentence));
- memcpy(szSentence, pApply->m_szSentence, nLength);
-
- switch (m_cMenuState.m_nState)
- {
- case PLAYER_MENU_STATE_NORMAL:
- case PLAYER_MENU_STATE_TRADEOPEN:
- m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADEOPEN, szSentence, nLength);
- break;
- case PLAYER_MENU_STATE_TEAMOPEN:
- if (m_cTeam.m_nFlag && m_cTeam.m_nID >= 0)
- g_Team[m_cTeam.m_nID].SetTeamClose();
- m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADEOPEN, szSentence, nLength);
- break;
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端申请取消待交易状态
- //-------------------------------------------------------------------------
- void KPlayer::TradeApplyClose(BYTE* pProtocol)
- {
- m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端申请开始交易
- //-------------------------------------------------------------------------
- void KPlayer::TradeApplyStart(BYTE* pProtocol)
- {
- if (this->CheckTrading())
- return;
-
- TRADE_APPLY_START_COMMAND *pStart = (TRADE_APPLY_START_COMMAND*)pProtocol;
-
- int nPlayer;
- nPlayer = FindAroundPlayer(pStart->m_dwID);
- if (nPlayer < 0)
- return;
- if (Player[nPlayer].m_cMenuState.m_nState != PLAYER_MENU_STATE_TRADEOPEN)
- return;
- this->m_cTrade.m_nApplyIdx = nPlayer;
-
- TRADE_APPLY_START_SYNC sApply;
- sApply.ProtocolType = s2c_tradeapplystart;
- sApply.m_nDestIdx = this->m_nPlayerIndex;
- sApply.m_dwNpcId = Npc[m_nIndex].m_dwID;
- if (g_pServer)
- g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sApply, sizeof(TRADE_APPLY_START_SYNC));
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:
- //-------------------------------------------------------------------------
- void KPlayer::TradeMoveMoney(BYTE* pProtocol)
- {
- if ( !CheckTrading() )
- return;
- if (this->m_cTrade.m_nTradeLock)
- return;
-
- int nMoney;
- TRADE_MOVE_MONEY_COMMAND *pMoney = (TRADE_MOVE_MONEY_COMMAND*)pProtocol;
- if (pMoney->m_nMoney < 0 || pMoney->m_nMoney > m_ItemList.GetEquipmentMoney())
- nMoney = 0;
- else
- nMoney = pMoney->m_nMoney;
- m_ItemList.TradeMoveMoney(nMoney);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:执行或取消交易
- //-------------------------------------------------------------------------
- void KPlayer::TradeDecision(BYTE* pProtocol)
- {
- if ( !CheckTrading() )
- return;
-
- TRADE_DECISION_COMMAND *pDecision = (TRADE_DECISION_COMMAND*)pProtocol;
-
- if (pDecision->m_btDecision == 2) // 己方锁定
- {
- if (this->m_cTrade.m_nTradeLock == 0)
- {
- this->m_cTrade.m_nTradeLock = 1;
- this->m_cTrade.m_nTradeState = 0;
- Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState = 0;
- }
-
- SyncTradeState();
- return;
- }
- else if (pDecision->m_btDecision == 3) // 锁定取消
- {
- if (this->m_cTrade.m_nTradeLock == 1)
- {
- // 取消己方锁定的同时也取消了对方的锁定
- this->m_cTrade.m_nTradeLock = 0;
- this->m_cTrade.m_nTradeState = 0;
- Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock = 0;
- Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState = 0;
- }
- SyncTradeState();
- return;
- }
- else if (pDecision->m_btDecision == 4) // 取消确定
- {
- if (m_cTrade.m_nTradeLock == 1 && Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock == 1)
- {
- m_cTrade.m_nTradeState = 0;
- SyncTradeState();
- }
- return;
- }
- else if (pDecision->m_btDecision == 0) // 取消交易
- {
- int nDestIdx;
- nDestIdx = this->m_cTrade.m_nTradeDest;
- // 取消交易的数据恢复
- this->m_ItemList.RecoverTrade();
- this->m_ItemList.ClearRoom(room_trade);
- this->m_ItemList.ClearRoom(room_trade1);
- this->m_cTrade.Release();
- Player[nDestIdx].m_ItemList.RecoverTrade();
- Player[nDestIdx].m_ItemList.ClearRoom(room_trade);
- Player[nDestIdx].m_ItemList.ClearRoom(room_trade1);
- Player[nDestIdx].m_cTrade.Release();
-
- TRADE_DECISION_SYNC sSync;
- sSync.ProtocolType = s2c_tradedecision;
- sSync.m_btDecision = 0;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
- g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
-
- // 取消交易的状态恢复(备份状态一定不会是 trading)(己方)
- this->m_cMenuState.RestoreBackupState(m_nPlayerIndex);
-
- // 取消交易的状态恢复(备份状态一定不会是 trading)(对方)
- Player[nDestIdx].m_cMenuState.RestoreBackupState(nDestIdx);
-
- return;
- }
- else if (pDecision->m_btDecision == 1) // 执行交易
- {
- // 如果双方没有同时锁定,不能确定
- if (this->m_cTrade.m_nTradeLock != 1 ||
- Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock != 1)
- {
- SyncTradeState();
- return;
- }
- // 对方还没确定,通知对方自己已确定
- else if (Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState == 0)
- {
- m_cTrade.m_nTradeState = 1;
-
- SyncTradeState();
-
- return;
- }
- // 对方已确定,执行交易
- else
- {
- // 执行交易之前,先检测一下是否有错误
- // -------------------- 检查 money --------------------
- int nSM1, nSM2, nDM1, nDM2;
- int nDestIdx = m_cTrade.m_nTradeDest;
- nSM1 = m_ItemList.GetMoney(room_equipment);
- nSM2 = m_ItemList.GetMoney(room_trade);
- nDM1 = Player[nDestIdx].m_ItemList.GetMoney(room_equipment);
- nDM2 = Player[nDestIdx].m_ItemList.GetMoney(room_trade);
- if (nSM2 < 0 || nSM1 + nDM2 - nSM2 < 0)
- {
- this->m_ItemList.TradeMoveMoney(0);
- // 通知客户端钱有问题 not end
- return;
- }
- if (nDM2 < 0 || nDM1 + nSM2 - nDM2 < 0)
- {
- Player[nDestIdx].m_ItemList.TradeMoveMoney(0);
- // 通知客户端钱有问题 not end
- return;
- }
- // ------------------ 检查 money end ------------------
-
- // --------- 检查双方物品栏能否接受买进的物品 ---------
- int nSelfCanGet, nDestCanGet;
-
- // 判断己方物品栏能否接受买进的物品
- Player[nDestIdx].m_ItemList.GetTradeRoomItemInfo();
- nSelfCanGet = m_ItemList.TradeCheckCanPlace();
- ItemSet.BackItemInfo();
-
- // 判断对方物品栏能否接受买进的物品
- this->m_ItemList.GetTradeRoomItemInfo();
- nDestCanGet = Player[nDestIdx].m_ItemList.TradeCheckCanPlace();
-
- if (!nSelfCanGet || !nDestCanGet)
- {
- if (!nSelfCanGet)
- {
- this->m_cTrade.m_nTradeState = 0;
-
- // 通知客户端买进的东西放不下
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- sMsg.m_wMsgID = enumMSG_ID_TRADE_SELF_ROOM_FULL;
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_wMsgID = enumMSG_ID_TRADE_DEST_ROOM_FULL;
- g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- }
- if (!nDestCanGet)
- {
- Player[nDestIdx].m_cTrade.m_nTradeState = 0;
-
- // 通知客户端买进的东西放不下
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- sMsg.m_wMsgID = enumMSG_ID_TRADE_SELF_ROOM_FULL;
- g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_wMsgID = enumMSG_ID_TRADE_DEST_ROOM_FULL;
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- }
- SyncTradeState();
- return;
- }
- // ------- 检查双方物品栏能否接受买进的物品 end -------
-
- // 通知客户端交易完成
- TRADE_DECISION_SYNC sSync;
- sSync.ProtocolType = s2c_tradedecision;
- sSync.m_btDecision = 1;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
- g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
-
- // 服务器端结束交易状态
- m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
- Player[nDestIdx].m_cMenuState.SetState(nDestIdx, PLAYER_MENU_STATE_NORMAL);
- this->m_cTrade.Release();
- Player[nDestIdx].m_cTrade.Release();
-
- // 交易中金钱的交换
- if (nSM2 <= nDM2)
- {
- this->Earn(nDM2 - nSM2);
- Player[nDestIdx].Pay(nDM2 - nSM2);
- }
- else
- {
- this->Pay(nSM2 - nDM2);
- Player[nDestIdx].Earn(nSM2 - nDM2);
- }
-
- //--------------- 交易中物品的交换 ---------------------
- // 对方的物品给己方
- int nPos;
- nPos = 0;
- while (1)
- {
- if (nPos >= TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT)
- break;
- if (!ItemSet.m_psBackItemInfo[nPos].m_nIdx)
- break;
- // 对方去除此物品
- Player[nDestIdx].m_ItemList.Remove(ItemSet.m_psBackItemInfo[nPos].m_nIdx);
- // 己方得到此物品
- m_ItemList.Add(
- ItemSet.m_psBackItemInfo[nPos].m_nIdx,
- pos_equiproom,
- ItemSet.m_psBackItemInfo[nPos].m_nX,
- ItemSet.m_psBackItemInfo[nPos].m_nY);
- nPos++;
- }
- // 己方的物品给对方
- nPos = 0;
- while (1)
- {
- if (nPos >= TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT)
- break;
- if (!ItemSet.m_psItemInfo[nPos].m_nIdx)
- break;
- // 己方去除此物品
- this->m_ItemList.Remove(ItemSet.m_psItemInfo[nPos].m_nIdx);
- // 对方得到此物品
- Player[nDestIdx].m_ItemList.Add(
- ItemSet.m_psItemInfo[nPos].m_nIdx,
- pos_equiproom,
- ItemSet.m_psItemInfo[nPos].m_nX,
- ItemSet.m_psItemInfo[nPos].m_nY);
- nPos++;
- }
- //------------- 交易中物品的交换 end -------------------
- return;
- }
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:执行或取消交易
- //-------------------------------------------------------------------------
- void KPlayer::c2sTradeReplyStart(BYTE* pProtocol)
- {
- if (this->CheckTrading())
- return;
- if (!pProtocol)
- return;
- TRADE_REPLY_START_COMMAND *pReply = (TRADE_REPLY_START_COMMAND*)pProtocol;
-
- int nPlayerIdx = pReply->m_nDestIdx;
- if (nPlayerIdx <= 0 || nPlayerIdx >= MAX_PLAYER)
- return;
- if (Player[nPlayerIdx].m_nIndex <= 0)
- return;
- if (Player[nPlayerIdx].m_cTrade.m_nApplyIdx != this->m_nPlayerIndex)
- return;
-
- // 拒绝
- if (pReply->m_bDecision == 0)
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TRADE_REFUSE_APPLY;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- sMsg.m_lpBuf = (LPVOID)Npc[m_nIndex].m_dwID;
- g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
- return;
- }
-
- if (this->m_cMenuState.m_nState != PLAYER_MENU_STATE_TRADEOPEN)
- {
- return;
- }
-
- // 如果处于队伍开放状态,关闭之
- if (Player[nPlayerIdx].m_cMenuState.m_nState == PLAYER_MENU_STATE_TEAMOPEN)
- {
- PLAYER_TEAM_OPEN_CLOSE sClose;
- sClose.m_btOpenClose = 0;
- Player[nPlayerIdx].SetTeamState((BYTE*)&sClose);
- }
- // 打坐的话,要站起来
- if (Npc[m_nIndex].m_Doing == do_sit)
- {
- Npc[m_nIndex].SendCommand(do_stand);
- }
- if (Npc[Player[nPlayerIdx].m_nIndex].m_Doing == do_sit)
- {
- Npc[Player[nPlayerIdx].m_nIndex].SendCommand(do_stand);
- }
-
- // 服务器的处理:改变状态,备份数据
- this->m_ItemList.StartTrade();
- this->m_cTrade.Release();
- this->m_cTrade.StartTrade(nPlayerIdx);
- this->m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADING, NULL, 0, Npc[Player[nPlayerIdx].m_nIndex].m_dwID);
-
- Player[nPlayerIdx].m_ItemList.StartTrade();
- Player[nPlayerIdx].m_cTrade.Release();
- Player[nPlayerIdx].m_cTrade.StartTrade(m_nPlayerIndex);
- Player[nPlayerIdx].m_cMenuState.SetState(nPlayerIdx, PLAYER_MENU_STATE_TRADING, NULL, 0, Npc[m_nIndex].m_dwID);
- }
- #endif
- //-------------------------------------------------------------------------
- // 功能:给交易双方的客户端发送交易状态信息
- //-------------------------------------------------------------------------
- #ifdef _SERVER
- void KPlayer::SyncTradeState()
- {
- if ( !CheckTrading() )
- return;
-
- TRADE_STATE_SYNC sSync;
- sSync.ProtocolType = s2c_tradepressoksync;
- sSync.m_btSelfLock = this->m_cTrade.m_nTradeLock;
- sSync.m_btDestLock = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock;
- sSync.m_btSelfOk = m_cTrade.m_nTradeState;
- sSync.m_btDestOk = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_STATE_SYNC));
-
- sSync.m_btSelfLock = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock;
- sSync.m_btDestLock = m_cTrade.m_nTradeLock;
- sSync.m_btSelfOk = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState;
- sSync.m_btDestOk = m_cTrade.m_nTradeState;
- g_pServer->PackDataToClient(Player[m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_STATE_SYNC));
- }
- #endif
- //-------------------------------------------------------------------------
- // 功能:发送自己装备在身上的装备信息给别人看
- //-------------------------------------------------------------------------
- #ifdef _SERVER
- void KPlayer::SendEquipItemInfo(int nTargetPlayer)
- {
- if (nTargetPlayer <= 0 || nTargetPlayer >= MAX_PLAYER || Player[nTargetPlayer].m_nIndex <= 0)
- return;
-
- int nIdx, i, j;
- SViewItemInfo *pInfo;
- VIEW_EQUIP_SYNC sView;
-
- sView.ProtocolType = s2c_viewequip;
- sView.m_dwNpcID = Npc[m_nIndex].m_dwID;
- for (i = 0; i < itempart_num; i++)
- {
- nIdx = m_ItemList.m_EquipItem[i];
- pInfo = &sView.m_sInfo[i];
- if (nIdx <= 0)
- {
- memset(pInfo, 0, sizeof(SViewItemInfo));
- continue;
- }
- pInfo->m_nID = Item[nIdx].GetID();
- pInfo->m_btGenre = Item[nIdx].GetGenre();
- pInfo->m_btDetail = Item[nIdx].GetDetailType();
- pInfo->m_btParticur = Item[nIdx].GetParticular();
- pInfo->m_btSeries = Item[nIdx].GetSeries();
- pInfo->m_btLevel = Item[nIdx].GetLevel();
- pInfo->m_btLuck = Item[nIdx].m_GeneratorParam.nLuck;
- pInfo->m_dwRandomSeed = Item[nIdx].m_GeneratorParam.uRandomSeed;
- pInfo->m_wVersion = Item[nIdx].m_GeneratorParam.nVersion;
- for (j = 0; j < 6; j++)
- pInfo->m_btMagicLevel[j] = (BYTE)Item[nIdx].m_GeneratorParam.nGeneratorLevel[j];
- }
-
- g_pServer->PackDataToClient(Player[nTargetPlayer].m_nNetConnectIdx, (BYTE*)&sView, sizeof(sView));
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:主角与传送门的相关的函数
- //-------------------------------------------------------------------------
- void KPlayer::UseTownPortal()
- {
- if (m_nPlayerIndex <= 0)
- return;
- if (m_nIndex <= 0)
- return;
- if (Npc[m_nIndex].m_SubWorldIndex < 0)
- return;
-
- if (!Npc[m_nIndex].m_FightMode)
- {
- return;
- }
-
- m_sPortalPos.m_nSubWorldId = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_SubWorldID;
- Npc[m_nIndex].GetMpsPos(&m_sPortalPos.m_nMpsX, &m_sPortalPos.m_nMpsY);
- m_sPortalPos.m_nTime = TOWN_PORTAL_TIME;
-
- Npc[m_nIndex].ChangeWorld(m_sDeathRevivalPos.m_nSubWorldID, m_sDeathRevivalPos.m_nMpsX, m_sDeathRevivalPos.m_nMpsY);
- Npc[m_nIndex].SetFightMode(0);
- }
- void KPlayer::BackToTownPortal()
- {
- if (m_nPlayerIndex <= 0)
- return;
- if (m_nIndex <= 0)
- return;
- if (m_sPortalPos.m_nTime <= 0)
- return;
-
- Npc[m_nIndex].ChangeWorld(m_sPortalPos.m_nSubWorldId, m_sPortalPos.m_nMpsX, m_sPortalPos.m_nMpsY);
- m_sPortalPos.m_nSubWorldId = 0;
- m_sPortalPos.m_nTime = 0;
- m_sPortalPos.m_nMpsX = 0;
- m_sPortalPos.m_nMpsY = 0;
- Npc[m_nIndex].SetFightMode(TRUE);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:主角死后重生
- //-------------------------------------------------------------------------
- void KPlayer::Revive(int nType)
- {
- int nSubWorldID = 0;
- int nMpsX = 0, nMpsY = 0;
- NPC_REVIVE_SYNC Sync;
- Sync.ProtocolType = s2c_playerrevive;
- Sync.ID = Npc[m_nIndex].m_dwID;
- Sync.Type = nType;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (const void*)&Sync, sizeof(NPC_REVIVE_SYNC));
- Npc[m_nIndex].BroadCastRevive(nType);
- switch(nType)
- {
- case REMOTE_REVIVE_TYPE:
- GetDeathRevivalPos(&nSubWorldID, &nMpsX, &nMpsY);
- Npc[m_nIndex].ChangeWorld(nSubWorldID, nMpsX, nMpsY);
- Npc[m_nIndex].m_FightMode = 0;
- break;
- case LOCAL_REVIVE_TYPE:
- Npc[m_nIndex].m_FightMode = 1;
- break;
- default:
- break;
- }
-
- Npc[m_nIndex].m_CurrentLife = Npc[m_nIndex].m_CurrentLifeMax;
- Npc[m_nIndex].m_CurrentMana = Npc[m_nIndex].m_CurrentManaMax;
- Npc[m_nIndex].m_CurrentStamina = Npc[m_nIndex].m_CurrentStaminaMax;
- //RestoreLiveData();
- Npc[m_nIndex].SendCommand(do_revive);
- }
- void KPlayer::RestoreLiveData()
- {
- Npc[m_nIndex].RestoreNpcBaseInfo();
- }
- BOOL KPlayer::Pay(int nMoney)
- {
- if (nMoney < 0)
- return FALSE;
-
- return m_ItemList.CostMoney(nMoney);
- }
- BOOL KPlayer::PrePay(int nMoney)
- {
- if (nMoney < 0)
- return FALSE;
- if (Pay(nMoney))
- {
- m_nPrePayMoney = nMoney;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- BOOL KPlayer::Earn(int nMoney)
- {
- if (nMoney < 0)
- return FALSE;
- return m_ItemList.AddMoney(room_equipment, nMoney);
- }
- //当服务器从数据库中获得玩家全部数据,并加载之后,使该玩家有效
- void KPlayer::LaunchPlayer()
- {
- int nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
- int nRegion = Npc[m_nIndex].m_RegionIndex;
- int nX = Npc[m_nIndex].m_MapX;
- int nY = Npc[m_nIndex].m_MapY;
- int nOffX = Npc[m_nIndex].m_OffX;
- int nOffY = Npc[m_nIndex].m_OffY;
- SubWorld[nSubWorld].AddPlayer(nRegion, m_nPlayerIndex);
- m_ulLastSaveTime = g_SubWorldSet.GetGameTime();
- if (SubWorld[nSubWorld].m_Region[nRegion].GetBarrierMin(nX, nY, nOffX, nOffY, FALSE) != Obstacle_NULL)
- {
- Npc[m_nIndex].ChangeWorld(m_sLoginRevivalPos.m_nSubWorldID, m_sLoginRevivalPos.m_nMpsX, m_sLoginRevivalPos.m_nMpsY);
- }
-
- }
- #endif
- BOOL KPlayer::ExecuteScript(char * ScriptFileName, char * szFunName, int nParam)
- {
- if (!ScriptFileName || !ScriptFileName[0] || !szFunName || !szFunName[0]) return FALSE;
- return ExecuteScript(g_FileName2Id(ScriptFileName), szFunName, nParam);
- }
- #define MAX_TRYEXECUTESCRIPT_COUNT 5
- BOOL KPlayer::ExecuteScript(DWORD dwScriptId, char * szFunName, int nParam)
- {
- /* bool bCanExecuteScript = true;
- //当前脚本未置空
- if (m_bWaitingPlayerFeedBack)
- {
- if (Npc[m_nIndex].m_ActionScriptID && (dwScriptId != Npc[m_nIndex].m_ActionScriptID))
- {
- m_btTryExecuteScriptTimes ++;
- if (m_btTryExecuteScriptTimes <= MAX_TRYEXECUTESCRIPT_COUNT)//最大尝试执行脚本的次数。如果超过后,就执行当前脚本,并放弃原来的脚本。
- {
- bCanExecuteScript = false;
- }
- else
- {
- m_btTryExecuteScriptTimes = 0;
- m_bWaitingPlayerFeedBack = false;
- Npc[m_nIndex].m_ActionScriptID = 0;
- }
- }
- }
-
- if (!bCanExecuteScript) return FALSE;
- */
- try
- {
- m_btTryExecuteScriptTimes = 0;
- bool bExecuteScriptMistake = true;
- KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId);
- if (pScript)
- {
- Npc[m_nIndex].m_ActionScriptID = dwScriptId;
- Lua_PushNumber(pScript->m_LuaState, m_nPlayerIndex);
- pScript->SetGlobalName(SCRIPT_PLAYERINDEX);
-
- Lua_PushNumber(pScript->m_LuaState, m_dwID);
- pScript->SetGlobalName(SCRIPT_PLAYERID);
-
- Lua_PushNumber(pScript->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
- pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX);
- int nTopIndex = 0;
-
- pScript->SafeCallBegin(&nTopIndex);
- if (pScript->CallFunction(szFunName,0, "d", nParam))
- {
- bExecuteScriptMistake = false;
- }
- pScript->SafeCallEnd(nTopIndex);
- }
-
- if (bExecuteScriptMistake)
- {
- m_bWaitingPlayerFeedBack = false;
- m_btTryExecuteScriptTimes = 0;
- Npc[m_nIndex].m_ActionScriptID = 0;
- return FALSE;
- }
-
- return TRUE;
- }
- catch(...)
- {
- printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
- m_bWaitingPlayerFeedBack = false;
- m_btTryExecuteScriptTimes = 0;
- Npc[m_nIndex].m_ActionScriptID = 0;
- return FALSE;
- }
- return TRUE;
- }
- BOOL KPlayer::ExecuteScript(DWORD dwScriptId, char * szFunName, char * szParams)
- {
- /*bool bCanExecuteScript = true;
- //当前脚本未置空
- if (m_bWaitingPlayerFeedBack)
- {
- if (Npc[m_nIndex].m_ActionScriptID && (dwScriptId != Npc[m_nIndex].m_ActionScriptID))
- {
- m_btTryExecuteScriptTimes ++;
- if (m_btTryExecuteScriptTimes <= MAX_TRYEXECUTESCRIPT_COUNT)//最大尝试执行脚本的次数。如果超过后,就执行当前脚本,并放弃原来的脚本。
- {
- bCanExecuteScript = false;
- }
- else
- {
- m_btTryExecuteScriptTimes = 0;
- m_bWaitingPlayerFeedBack = false;
- Npc[m_nIndex].m_ActionScriptID = 0;
- }
- }
- }
-
- bCanExecuteScript = true;//test
-
- if (!bCanExecuteScript) return FALSE;
- */
-
- try
- {
- m_btTryExecuteScriptTimes = 0;
- bool bExecuteScriptMistake = true;
- KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId);
- int nTopIndex = 0;
-
- if (pScript)
- {
- Npc[m_nIndex].m_ActionScriptID = dwScriptId;
- Lua_PushNumber(pScript->m_LuaState, m_nPlayerIndex);
- pScript->SetGlobalName(SCRIPT_PLAYERINDEX);
-
- Lua_PushNumber(pScript->m_LuaState, m_dwID);
- pScript->SetGlobalName(SCRIPT_PLAYERID);
-
- Lua_PushNumber(pScript->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
- pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX);
-
- pScript->SafeCallBegin(&nTopIndex);
-
- if ( (!szParams) || !szParams[0])
- {
- if (pScript->CallFunction(szFunName, 0,""))
- {
- bExecuteScriptMistake = false;
- }
- }
- else
- {
- if (pScript->CallFunction(szFunName,0, "sd", szParams,0))
- {
- bExecuteScriptMistake = false;
- }
- }
- pScript->SafeCallEnd(nTopIndex);
- }
-
- if (bExecuteScriptMistake)
- {
- m_bWaitingPlayerFeedBack = false;
- m_btTryExecuteScriptTimes = 0;
- Npc[m_nIndex].m_ActionScriptID = 0;
- return FALSE;
- }
- return TRUE;
- }
- catch(...)
- {
- printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
- m_bWaitingPlayerFeedBack = false;
- m_btTryExecuteScriptTimes = 0;
- Npc[m_nIndex].m_ActionScriptID = 0;
- return FALSE;
- }
- return TRUE;
- }
- BOOL KPlayer::ExecuteScript(char * ScriptFileName, char * szFunName, char * szParams)
- {
- if (!ScriptFileName || !ScriptFileName[0] || !szFunName || !szFunName[0]) return FALSE;
- DWORD dwScriptId = g_FileName2Id(ScriptFileName);
- return ExecuteScript(dwScriptId, szFunName, szParams);
- }
- BOOL KPlayer::DoScript(char * ScriptCommand)
- {
- if (NULL == ScriptCommand) return FALSE;
- KLuaScript *Script = new KLuaScript;
- Script->Init();
- Script->RegisterFunctions(GameScriptFuns, g_GetGameScriptFunNum());
-
- //GM Standand Script Functions
- Script->Load("\script\gmscript.lua");
-
-
- Lua_PushNumber(Script->m_LuaState, m_nPlayerIndex);
- Script->SetGlobalName(SCRIPT_PLAYERINDEX);
- Lua_PushNumber(Script->m_LuaState, m_dwID);
- Script->SetGlobalName(SCRIPT_PLAYERID);
-
- Lua_PushNumber(Script->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
- Script->SetGlobalName(SCRIPT_SUBWORLDINDEX);
-
- if (Script->LoadBuffer((PBYTE)ScriptCommand, strlen(ScriptCommand)))
- {
- BOOL bResult = Script->ExecuteCode();
- delete Script; //Question!
- return bResult;
- }
- delete Script; //Question!
- return FALSE;
- }
- void KPlayer::DoScriptAction(PLAYER_SCRIPTACTION_SYNC * pUIInfo) //要求显示某个UI界面
- {
- if (!pUIInfo) return;
-
- //服务器端脚本时
- if (pUIInfo->m_bParam2 == 1)
- {
- #ifdef _SERVER
- pUIInfo->ProtocolType = (BYTE)s2c_scriptaction;
- pUIInfo->m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + pUIInfo->m_nBufferLen - 1;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)pUIInfo, pUIInfo->m_wProtocolLong + 1 );
- #else
- }
- else //客户端脚本要求显示脚本 直接运行
- {
- OnScriptAction((PLAYER_SCRIPTACTION_SYNC *)pUIInfo);
- #endif
- }
-
- }
- //服务器端获知玩家选择了某项后,处理~~
- void KPlayer::ProcessPlayerSelectFromUI(BYTE* pProtocol) // 处理当玩家从选择菜单选择某项时的操作
- {
- PLAYER_SELECTUI_COMMAND * pSelUI = (PLAYER_SELECTUI_COMMAND*) pProtocol;
- m_bWaitingPlayerFeedBack = false;
- //如果返回负数,表示退出该脚本执行环境
- if (pSelUI->nSelectIndex < 0) m_nAvailableAnswerNum = 0;
- if (m_nAvailableAnswerNum > pSelUI->nSelectIndex)
- {
- if (m_szTaskAnswerFun[pSelUI->nSelectIndex][0])
- {
- // g_SetFilePath("\script");
- if (m_nIndex)
- {
- ExecuteScript(Npc[m_nIndex].m_ActionScriptID, m_szTaskAnswerFun[pSelUI->nSelectIndex], pSelUI->nSelectIndex);
- }
- }
- }
- }
- #ifndef _SERVER
- //玩家在界面交互后,选择了某项后,向服务器端发送
- void KPlayer::OnSelectFromUI(PLAYER_SELECTUI_COMMAND * pSelectUI, UIInfo eUIInfo) //当玩家从选择框中选择某项后,将向服务器发送
- {
- if (!pSelectUI) return;
-
- switch(eUIInfo)
- {
- case UI_SELECTDIALOG:
- {
- if (g_bUISelIntelActiveWithServer)
- {
- pSelectUI->ProtocolType = (BYTE)c2s_playerselui;
- if (g_pClient)
- g_pClient->SendPackToServer((BYTE*)pSelectUI, sizeof(PLAYER_SELECTUI_COMMAND));
- }
- else
- {
- ProcessPlayerSelectFromUI((BYTE *)pSelectUI); // 处理当玩家从选择菜单选择某项时的操作
- }
- }
- break;
- case UI_TALKDIALOG:
- {
- if (g_bUISpeakActiveWithServer)
- {
- pSelectUI->ProtocolType = (BYTE)c2s_playerselui;
- if (g_pClient)
- g_pClient->SendPackToServer((BYTE*)pSelectUI, sizeof(PLAYER_SELECTUI_COMMAND));
- }
- else
- {
- ProcessPlayerSelectFromUI((BYTE *)pSelectUI); // 处理当玩家从选择菜单选择某项时的操作
- }
-
- }break;
- }
- }
- #endif
- //-------------------------------------------------------------------------
- // 功能:获得通知某好友上线了
- //-------------------------------------------------------------------------
- void KPlayer::ChatFriendOnLine(DWORD dwID, int nFriendIdx)
- {
- if (nFriendIdx <= 0)
- return;
- for (int i = 0; i < MAX_FRIEND_TEAM; i++)
- {
- if (m_cChat.m_cFriendTeam[i].m_nFriendNo == 0)
- continue;
- CChatFriend *pFriend;
- pFriend = (CChatFriend*)m_cChat.m_cFriendTeam[i].m_cEveryOne.GetHead();
- while (pFriend)
- {
- if (pFriend->m_dwID == dwID)
- {
- pFriend->m_nPlayerIdx = nFriendIdx;
- #ifdef _SERVER
- CHAT_FRIEND_ONLINE_SYNC sFriend;
- sFriend.ProtocolType = s2c_chatfriendonline;
- sFriend.m_dwID = dwID;
- sFriend.m_nPlayerIdx = nFriendIdx;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sFriend, sizeof(CHAT_FRIEND_ONLINE_SYNC));
- #else
- // 通知界面有好友上线
- KUiPlayerItem sPlayer;
- strcpy(sPlayer.Name, pFriend->m_szName);
- sPlayer.uId = dwID;
- sPlayer.nIndex = nFriendIdx;
- sPlayer.nData = CHAT_S_ONLINE;
- CoreDataChanged(GDCNI_CHAT_FRIEND_STATUS, (unsigned int)&sPlayer, i);
-
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_CHAT_FRIEND_ONLINE, pFriend->m_szName);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- #endif
- return;
- }
- pFriend = (CChatFriend*)pFriend->GetNext();
- }
- }
- #ifdef _SERVER
- // 如果没找到,说明本方已经删除了对方,必须通知对方删除
- Player[nFriendIdx].m_cChat.DeleteFriendData(m_dwID, nFriendIdx);
- #endif
- }
- // 获得当前门派名称
- void KPlayer::GetFactionName(char *lpszName, int nSize)
- {
- this->m_cFaction.GetCurFactionName(lpszName);
- return;
- }
- #ifdef _SERVER
- void KPlayer::S2CExecuteScript(char * ScriptName, char * szParam = NULL)
- {
- if (!ScriptName || (!ScriptName[0])) return;
-
- PLAYER_SCRIPTACTION_SYNC ScriptAction;
- ScriptAction.m_nOperateType = SCRIPTACTION_EXESCRIPT;
- ScriptAction.ProtocolType = s2c_scriptaction;
- char * script = NULL;
- if (szParam == NULL || szParam[0] == 0)
- {
- ScriptAction.m_nBufferLen = strlen(ScriptName) + 1 ;
- strcpy(ScriptAction.m_pContent, ScriptName);
- }
- else
- {
- ScriptAction.m_nBufferLen = strlen(ScriptName) + 2 + strlen(szParam);
- sprintf(ScriptAction.m_pContent, "%s|%s", ScriptName, szParam);
- }
- ScriptAction.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - 300 + ScriptAction.m_nBufferLen - 1;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&ScriptAction, sizeof(PLAYER_SCRIPTACTION_SYNC) - 300 + ScriptAction.m_nBufferLen);
-
- }
- #endif
- #ifndef _SERVER
- void KPlayer::OnScriptAction(PLAYER_SCRIPTACTION_SYNC * pMsg)
- {
- PLAYER_SCRIPTACTION_SYNC * pScriptAction = (PLAYER_SCRIPTACTION_SYNC *)pMsg;
- char szString[1000];
-
- switch(pScriptAction->m_nOperateType)
- {
- case SCRIPTACTION_UISHOW:
- {
- switch(pScriptAction->m_bUIId)
- {
- case UI_SELECTDIALOG://通知客户端显示选择窗口
- {
- KUiQuestionAndAnswer *pQuest = NULL;
- if (pScriptAction->m_nBufferLen <= 0) break;
-
- if (pScriptAction->m_bOptionNum <= 0)
- pQuest = (KUiQuestionAndAnswer *)malloc(sizeof(KUiQuestionAndAnswer));
- else
- pQuest = (KUiQuestionAndAnswer *)malloc(sizeof(KUiQuestionAndAnswer) + sizeof(KUiAnswer) * (pScriptAction->m_bOptionNum - 1));
-
- char strContent[1024];
- char * pAnswer = NULL;
- pQuest->AnswerCount = 0;
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(strContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen + 1);
- pAnswer = strstr(strContent, "|");
- if (!pAnswer)
- {
- pScriptAction->m_bOptionNum = 0;
- pQuest->AnswerCount = 0;
- }
- else
- *pAnswer++ = 0;
-
- g_StrCpyLen(pQuest->Question, strContent, sizeof(pQuest->Question));
- pQuest->QuestionLen = TEncodeText(pQuest->Question, strlen(pQuest->Question));
- }
- //主信息为数字标识
- else
- {
- g_StrCpyLen(pQuest->Question, g_GetStringRes(*(int *)pScriptAction->m_pContent, szString, 1000), sizeof(pQuest->Question));
- pQuest->QuestionLen = TEncodeText(pQuest->Question, strlen(pQuest->Question));
-
- g_StrCpyLen(strContent, pScriptAction->m_pContent + sizeof(int), pScriptAction->m_nBufferLen - sizeof(int) + 1);
- pAnswer = strContent + 1;
- }
-
- for (int i = 0; i < pScriptAction->m_bOptionNum; i ++)
- {
- char * pNewAnswer = strstr(pAnswer, "|");
-
- if (pNewAnswer)
- {
- *pNewAnswer = 0;
- strcpy(pQuest->Answer[i].AnswerText, pAnswer);
- pQuest->Answer[i].AnswerLen = -1;
- pAnswer = pNewAnswer + 1;
- }
- else
- {
- strcpy(pQuest->Answer[i].AnswerText, pAnswer);
- pQuest->Answer[i].AnswerLen = -1;
- pQuest->AnswerCount = i + 1;
- break;
- }
- }
-
- g_bUISelIntelActiveWithServer = pScriptAction->m_bParam2;
- g_bUISelLastSelCount = pQuest->AnswerCount;
- CoreDataChanged(GDCNI_QUESTION_CHOOSE,(unsigned int) pQuest, 0);
- free(pQuest);
- pQuest = NULL;
- }
- break;
-
- case UI_TALKDIALOG:
- {
- BOOL bUsingSpeakId = pScriptAction->m_bParam1;
- int nSentenceCount = pScriptAction->m_bOptionNum;
- if (nSentenceCount <= 0) return ;
- KUiInformationParam *pSpeakList = new KUiInformationParam[nSentenceCount];
- memset(pSpeakList, 0, sizeof(KUiInformationParam) * nSentenceCount);
-
- char * pAnswer = new char [pScriptAction->m_nBufferLen + 1];
- char * pBackupAnswer = pAnswer;
- g_StrCpyLen(pAnswer, pScriptAction->m_pContent, pScriptAction->m_nBufferLen + 1);
-
- int nCount = 0;
- for (int i = 0; i < pScriptAction->m_bOptionNum; i ++)
- {
- char * pNewAnswer = strstr(pAnswer, "|");
-
- if (pNewAnswer)
- {
- *pNewAnswer = 0;
- if (!bUsingSpeakId)
- {
- strcpy(pSpeakList[i].sInformation, pAnswer);
-
- }
- else
- {
- strcpy(pSpeakList[i].sInformation, g_GetStringRes(atoi(pAnswer), szString, sizeof(szString)));
- }
-
-
- if (i < pScriptAction->m_bOptionNum - 1)
- strcpy(pSpeakList[i].sConfirmText, "继续");
- else
- {
- strcpy(pSpeakList[i].sConfirmText, "完成");
- if (pScriptAction->m_nParam == 1)
- pSpeakList[i].bNeedConfirmNotify = TRUE;
-
- }
- pSpeakList[i].nInforLen = TEncodeText(pSpeakList[i].sInformation, strlen(pSpeakList[i].sInformation));
- pAnswer = pNewAnswer + 1;
- }
- else
- {
- if (!bUsingSpeakId)
- {
- strcpy(pSpeakList[i].sInformation, pAnswer);
- }
- else
- {
- strcpy(pSpeakList[i].sInformation, g_GetStringRes(atoi(pAnswer), szString ,sizeof(szString)));
- }
-
- strcpy(pSpeakList[i].sConfirmText, "完成");
-
- if (pScriptAction->m_nParam == 1)
- pSpeakList[i].bNeedConfirmNotify = TRUE;
-
- pSpeakList[i].nInforLen = TEncodeText(pSpeakList[i].sInformation, strlen(pSpeakList[i].sInformation));
- nCount++;
- break;
- }
- nCount ++;
- }
- if (pBackupAnswer)
- {
- delete []pBackupAnswer;
- pBackupAnswer = NULL;
- }
- g_bUISpeakActiveWithServer = pScriptAction->m_bParam2;
- CoreDataChanged(GDCNI_SPEAK_WORDS,(unsigned int)pSpeakList, nCount);
- if (pSpeakList)
- {
- delete pSpeakList;
- pSpeakList = NULL;
- }
- }
- break;
- case UI_NOTEINFO:
- {
- if (pScriptAction->m_nBufferLen <= 0)
- break;
- KMissionRecord Record;
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(Record.sContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen - sizeof(int) - 1);
- Record.uValue = *(unsigned int*) (pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(int));
- }
- else
- {
- g_GetStringRes(*(int *)pScriptAction->m_pContent, Record.sContent ,sizeof(Record.sContent));
- Record.uValue = *(unsigned int* ) (Record.sContent + sizeof(int));
- }
-
-
- Record.nContentLen = TEncodeText(Record.sContent, strlen(Record.sContent));
-
- CoreDataChanged(GDCNI_MISSION_RECORD, (unsigned long)&Record, 0);
-
- }
- break;
- case UI_MSGINFO:
- {
- if (pScriptAction->m_nBufferLen <= 0)
- break;
-
- char strContent[1024];
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(strContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen + 1);
- }
- else
- {
- g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
- }
-
- KSystemMessage sMsg;
- sMsg.eType = SMT_PLAYER;
- sMsg.byConfirmType = SMCT_MSG_BOX;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- g_StrCpyLen(sMsg.szMessage, strContent, sizeof(sMsg.szMessage));
-
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- //CoreDataChanged(GDCNI_MISSION_RECORD, (unsigned int)strContent, strlen(strContent));
-
- }break;
-
- case UI_NEWSINFO:
- {
- if (pScriptAction->m_nBufferLen <= 0)
- break;
- switch(pScriptAction->m_bOptionNum) //OPtionNum代表是哪一种News类型
- {
- case NEWSMESSAGE_NORMAL:
- {
-
- KNewsMessage News;
- News.nType = NEWSMESSAGE_NORMAL;
-
- char strContent[1024];
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(strContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen + 1);
- }
- else
- {
- g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
- }
-
- g_StrCpyLen(News.sMsg, strContent, sizeof(News.sMsg));
- News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
- CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, 0);
- }
- break;
- //STRING|STRINGID + TIME(INT)
- case NEWSMESSAGE_COUNTING:
- {
- KNewsMessage News;
- News.nType = pScriptAction->m_bOptionNum;
-
- char strContent[1024];
- int nTime = 0;
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(strContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen - sizeof(int) + 1);
- }
- else
- {
- g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
- }
-
- g_StrCpyLen(News.sMsg, strContent, sizeof(News.sMsg));
- News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
- SYSTEMTIME systime;
-
- memset(&systime, 0, sizeof(SYSTEMTIME));
- systime.wSecond = *(int *)((pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(int)));
-
- CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, (unsigned int)&systime);
-
- }break;
- case NEWSMESSAGE_TIMEEND:
- {
- KNewsMessage News;
- News.nType = pScriptAction->m_bOptionNum;
-
- char strContent[1024];
- int nTime = 0;
- //主信息为字符串
- if (pScriptAction->m_bParam1 == 0)
- {
- g_StrCpyLen(strContent, pScriptAction->m_pContent, pScriptAction->m_nBufferLen - sizeof(SYSTEMTIME) + 1);
- }
- else
- {
- g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
- }
-
- g_StrCpyLen(News.sMsg, strContent, sizeof(News.sMsg));
- News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
- SYSTEMTIME systime;
- systime = *(SYSTEMTIME*)((pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(SYSTEMTIME)));
- CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, (unsigned int)&systime);
-
- }break;
-
- }
-
- }break;
- case UI_PLAYMUSIC:
- {
- char szMusicFile[MAX_PATH];
- memcpy(szMusicFile, pScriptAction->m_pContent, pScriptAction->m_nBufferLen);
- szMusicFile[pScriptAction->m_nBufferLen] = 0;
- g_SubWorldSet.m_cMusic.ScriptPlay(szMusicFile);
- }break;
-
- case UI_OPENTONGUI:
- {
- Player[CLIENT_PLAYER_INDEX].m_cTong.OpenCreateInterface();
- break;
- }
- }
- } break;
- case SCRIPTACTION_EXESCRIPT://要求客户端调用某个脚本
- {
- if (pScriptAction->m_nBufferLen <= 0 ) break;
- char szScriptInfo[1000];
- g_StrCpyLen(szScriptInfo, pScriptAction->m_pContent,pScriptAction->m_nBufferLen + 1);
- char * pDivPos = strstr(szScriptInfo, "/");
- if (pDivPos) *pDivPos++ = 0;
- if (pDivPos)
- ExecuteScript(szScriptInfo, "OnCall", pDivPos);
- else
- ExecuteScript(szScriptInfo, "OnCall", "");
- }
- break;
- }
-
-
- }
- #endif
- #ifdef _SERVER
- int KPlayer::AddTempTaskValue(void* pData)
- {
- memcpy(m_cTask.nClear, pData, sizeof(int) * MAX_TEMP_TASK);
- return 1;
- }
- //客户端请求与某个Npc对话
- //服务器版本
- void KPlayer::DialogNpc(BYTE * pProtocol)
- {
- //if (m_nAvailableAnswerNum > 0) return ;
- PLAYER_DIALOG_NPC_COMMAND * pDialogNpc = (PLAYER_DIALOG_NPC_COMMAND*) pProtocol;
- int nIdx = 0;
- if (pDialogNpc->nNpcId < 0) return;
- nIdx = FindAroundNpc(pDialogNpc->nNpcId);//NpcSet.SearchID(pDialogNpc->nNpcId);
- if (nIdx > 0)
- {
- int distance = NpcSet.GetDistance(nIdx, m_nIndex);
- // 小于对话半径就开始对话
- if ((Npc[nIdx].m_Kind == kind_dialoger) ||
- (NpcSet.GetRelation(m_nIndex, nIdx) == relation_none))
- {
- if (distance <= Npc[nIdx].m_DialogRadius * 2) // 放大server对话半径
- {
- if (Npc[nIdx].ActionScript[0])
- {
- ExecuteScript(Npc[nIdx].m_ActionScriptID, "main", "");
- }
- }
- }
- }
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cTradeChangeState(BYTE* pMsg)
- {
- TRADE_CHANGE_STATE_SYNC *pTrade = (TRADE_CHANGE_STATE_SYNC*)pMsg;
-
-
- switch (m_cMenuState.m_nState)
- {
- case PLAYER_MENU_STATE_NORMAL: // 当前客户端 NORMAL
- case PLAYER_MENU_STATE_TRADEOPEN: // 当前客户端 TRADEOPEN
- if (pTrade->m_btState == 0)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 1)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 2)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_TRADING);
- m_cTrade.StartTrade(pTrade->m_dwNpcID);
- m_ItemList.StartTrade();
-
- // 通知界面进入交易界面
- KUiPlayerItem sTradePlayer;
- int nIdx;
-
- nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
- if (nIdx > 0)
- strcpy(sTradePlayer.Name, Npc[nIdx].Name);
- else
- sTradePlayer.Name[0] = 0;
- sTradePlayer.nIndex = 0;
- sTradePlayer.uId = 0;
- sTradePlayer.nData = 0;
- CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
-
- if (Npc[m_nIndex].m_Doing == do_sit)
- {
- Npc[m_nIndex].SendCommand(do_stand);
- }
- }
- break;
- case PLAYER_MENU_STATE_TEAMOPEN: // 当前客户端 TEAMOPEN
- g_Team[0].SetTeamClose();
- if (pTrade->m_btState == 0)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 1)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 2)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_TRADING);
- m_cTrade.StartTrade(pTrade->m_dwNpcID);
- m_ItemList.StartTrade();
-
- // 通知界面进入交易界面
- KUiPlayerItem sTradePlayer;
- int nIdx;
-
- nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
- if (nIdx > 0)
- strcpy(sTradePlayer.Name, Npc[nIdx].Name);
- else
- sTradePlayer.Name[0] = 0;
- sTradePlayer.Name[0] = 0;
- sTradePlayer.nIndex = 0;
- sTradePlayer.uId = 0;
- sTradePlayer.nData = 0;
- CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
-
- if (Npc[m_nIndex].m_Doing == do_sit)
- {
- Npc[m_nIndex].SendCommand(do_stand);
- }
- }
- break;
- case PLAYER_MENU_STATE_TRADING: // 当前客户端 TRADING
- // 当客户端处于 TRADING 时,不应该收到此协议
- if (pTrade->m_btState == 0)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 1)
- {
- m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
- CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
- }
- else if (pTrade->m_btState == 2) // 客户端此时不应该在这个状态,客户端已出错
- {
- m_cMenuState.m_nState = PLAYER_MENU_STATE_TRADING;
- m_cMenuState.m_nTradeDest = pTrade->m_dwNpcID;
- m_cMenuState.m_nTradeState = 0;
- m_cMenuState.m_nTradeDestState = 0;
- this->m_ItemList.RecoverTrade();
- this->m_ItemList.BackupTrade();
- this->m_ItemList.ClearRoom(room_trade);
- this->m_ItemList.ClearRoom(room_trade1);
-
- // 通知界面进入交易界面
- KUiPlayerItem sTradePlayer;
- int nIdx;
-
- nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
- if (nIdx > 0)
- strcpy(sTradePlayer.Name, Npc[nIdx].Name);
- else
- sTradePlayer.Name[0] = 0;
- sTradePlayer.Name[0] = 0;
- sTradePlayer.nIndex = 0;
- sTradePlayer.uId = 0;
- sTradePlayer.nData = 0;
- CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
-
- if (Npc[m_nIndex].m_Doing == do_sit)
- {
- Npc[m_nIndex].SendCommand(do_stand);
- }
- }
- break;
- }
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cLevelUp(BYTE* pMsg)
- {
- PLAYER_LEVEL_UP_SYNC *pLevel = (PLAYER_LEVEL_UP_SYNC*)pMsg;
- if ((DWORD)Npc[m_nIndex].m_Level < (DWORD)pLevel->m_btLevel && m_nExp < PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level))
- {
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_GET_EXP, PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level) - m_nExp);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
-
- m_nExp = 0;
- Npc[m_nIndex].m_Level = (DWORD)pLevel->m_btLevel;
- m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level);
-
- // -------------------------- 等级增加时各项属性同步 ----------------------
- // 同步未分配属性点
- if (pLevel->m_nAttributePoint > m_nAttributePoint)
- {
- KSystemMessage Msg;
- sprintf(Msg.szMessage, MSG_GET_ATTRIBUTE_POINT, pLevel->m_nAttributePoint - m_nAttributePoint);
- Msg.eType = SMT_PLAYER;
- Msg.byConfirmType = SMCT_UI_ATTRIBUTE;
- Msg.byPriority = 3;
- Msg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
- }
- m_nAttributePoint = pLevel->m_nAttributePoint;
-
- // 同步未分配技能点
- if (m_nSkillPoint < pLevel->m_nSkillPoint)
- {
- KSystemMessage Msg;
- sprintf(Msg.szMessage, MSG_GET_SKILL_POINT, pLevel->m_nSkillPoint - m_nSkillPoint);
- Msg.eType = SMT_PLAYER;
- Msg.byConfirmType = SMCT_UI_SKILLS;
- Msg.byPriority = 3;
- Msg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
- }
- m_nSkillPoint = pLevel->m_nSkillPoint;
-
- // 处理生命、体力、内力值(影响基本生命、体力、内力最大值的因素:等级、属性点,影响当前生命最大值的因素:装备、技能、药物(临时))
- Npc[m_nIndex].m_LifeMax = pLevel->m_nBaseLifeMax;
- Npc[m_nIndex].m_StaminaMax = pLevel->m_nBaseStaminaMax;
- Npc[m_nIndex].m_ManaMax = pLevel->m_nBaseManaMax;
- // Npc[m_nIndex].ResetLifeReplenish();
- Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
- Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
- Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
-
- // 处理各种抗性的变化 火、冰、毒、电、物理
- Npc[m_nIndex].m_FireResist = PlayerSet.m_cLevelAdd.GetFireResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_CurrentFireResist = Npc[m_nIndex].m_FireResist;
- Npc[m_nIndex].m_ColdResist = PlayerSet.m_cLevelAdd.GetColdResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_CurrentColdResist = Npc[m_nIndex].m_ColdResist;
- Npc[m_nIndex].m_PoisonResist = PlayerSet.m_cLevelAdd.GetPoisonResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_CurrentPoisonResist = Npc[m_nIndex].m_PoisonResist;
- Npc[m_nIndex].m_LightResist = PlayerSet.m_cLevelAdd.GetLightResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_CurrentLightResist = Npc[m_nIndex].m_LightResist;
- Npc[m_nIndex].m_PhysicsResist = PlayerSet.m_cLevelAdd.GetPhysicsResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_CurrentPhysicsResist = Npc[m_nIndex].m_PhysicsResist;
- Npc[m_nIndex].m_FireResistMax = BASE_FIRE_RESIST_MAX;
- Npc[m_nIndex].m_ColdResistMax = BASE_COLD_RESIST_MAX;
- Npc[m_nIndex].m_PoisonResistMax = BASE_POISON_RESIST_MAX;
- Npc[m_nIndex].m_LightResistMax = BASE_LIGHT_RESIST_MAX;
- Npc[m_nIndex].m_PhysicsResistMax = BASE_PHYSICS_RESIST_MAX;
- Npc[m_nIndex].m_CurrentFireResistMax = Npc[m_nIndex].m_FireResistMax;
- Npc[m_nIndex].m_CurrentColdResistMax = Npc[m_nIndex].m_ColdResistMax;
- Npc[m_nIndex].m_CurrentPoisonResistMax = Npc[m_nIndex].m_PoisonResistMax;
- Npc[m_nIndex].m_CurrentLightResistMax = Npc[m_nIndex].m_LightResistMax;
- Npc[m_nIndex].m_CurrentPhysicsResistMax = Npc[m_nIndex].m_PhysicsResistMax;
-
- int nOldCurCamp = Npc[m_nIndex].m_CurrentCamp;
- // 根据装备、技能信息更新当前数据
- this->UpdataCurData();
- SetNpcPhysicsDamage();
- Npc[m_nIndex].m_CurrentCamp = nOldCurCamp;
-
- // 生命、体力、内力值加满
- Npc[m_nIndex].m_CurrentLife = Npc[m_nIndex].m_CurrentLifeMax;
- Npc[m_nIndex].m_CurrentStamina = Npc[m_nIndex].m_CurrentStaminaMax;
- Npc[m_nIndex].m_CurrentMana = Npc[m_nIndex].m_CurrentManaMax;
-
- // 客户端队伍中自己的等级加一
- if (this->m_cTeam.m_nFlag)
- {
- if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
- {
- g_Team[0].m_nMemLevel[0] = Npc[m_nIndex].m_Level;
- }
- else
- {
- for (int i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if ((DWORD)g_Team[0].m_nMember[i] == Npc[m_nIndex].m_dwID)
- {
- g_Team[0].m_nMemLevel[i] = Npc[m_nIndex].m_Level;
- break;
- }
- }
- }
- }
-
- KSystemMessage Msg;
-
- Msg.byConfirmType = SMCT_CLICK;
- Msg.byParamSize = 0;
- Msg.byPriority = 1;
- Msg.eType = SMT_PLAYER;
- sprintf(Msg.szMessage, MSG_LEVEL_UP, Npc[m_nIndex].m_Level);
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
-
- Npc[this->m_nIndex].SetInstantSpr(enumINSTANT_STATE_LEVELUP);
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cGetCurAttribute(BYTE* pMsg)
- {
- PLAYER_ATTRIBUTE_SYNC *pAttribute = (PLAYER_ATTRIBUTE_SYNC*)pMsg;
- m_nAttributePoint = pAttribute->m_nLeavePoint;
- int nData;
- switch (pAttribute->m_btAttribute)
- {
- case ATTRIBUTE_STRENGTH:
- nData = pAttribute->m_nBasePoint - m_nStrength;
- m_nStrength = pAttribute->m_nBasePoint;
- m_nCurStrength = pAttribute->m_nCurPoint;
- UpdataCurData();
- SetNpcPhysicsDamage();
- break;
- case ATTRIBUTE_DEXTERITY:
- nData = pAttribute->m_nBasePoint - m_nDexterity;
- m_nDexterity = pAttribute->m_nBasePoint;
- SetNpcAttackRating();
- SetNpcDefence();
- UpdataCurData();
- SetNpcPhysicsDamage();
- break;
- case ATTRIBUTE_VITALITY:
- nData = pAttribute->m_nBasePoint - m_nVitality;
- m_nVitality = pAttribute->m_nBasePoint;
- Npc[m_nIndex].AddBaseLifeMax(PlayerSet.m_cLevelAdd.GetLifePerVitality(Npc[m_nIndex].m_Series) * nData);
- Npc[m_nIndex].AddBaseStaminaMax(PlayerSet.m_cLevelAdd.GetStaminaPerVitality(Npc[m_nIndex].m_Series) * nData);
- UpdataCurData();
- break;
- case ATTRIBUTE_ENGERGY:
- nData = pAttribute->m_nBasePoint - m_nEngergy;
- m_nEngergy = pAttribute->m_nBasePoint;
- Npc[m_nIndex].AddBaseManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
- UpdataCurData();
- break;
- }
- CoreDataChanged(GDCNI_PLAYER_RT_ATTRIBUTE, 0, 0);
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cSetExp(int nExp)
- {
- if (nExp > m_nExp)
- {
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_GET_EXP, nExp - m_nExp);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
- else if (nExp < m_nExp)
- {
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_DEC_EXP, m_nExp - nExp);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
-
- this->m_nExp = nExp;
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cSyncMoney(BYTE* pMsg)
- {
- PLAYER_MONEY_SYNC *pMoney = (PLAYER_MONEY_SYNC*)pMsg;
-
- if ( CheckTrading() )
- {
- if (pMoney->m_nMoney1 >= pMoney->m_nMoney3)
- {
- m_ItemList.SetMoney(pMoney->m_nMoney1 - pMoney->m_nMoney3, pMoney->m_nMoney2, pMoney->m_nMoney3);
- }
- else
- {
- m_ItemList.SetMoney(0, pMoney->m_nMoney2 + pMoney->m_nMoney1 - pMoney->m_nMoney3, pMoney->m_nMoney3);
- }
- m_cTrade.m_nTradeState = 0;
- m_cTrade.m_nTradeDestState = 0;
- m_cTrade.m_nBackEquipMoney = pMoney->m_nMoney1;
- m_cTrade.m_nBackRepositoryMoney = pMoney->m_nMoney2;
- }
- else
- {
- // 捡钱一定是到room_equipment
- int nMoney1 = m_ItemList.GetMoney(room_equipment);
- if (pMoney->m_nMoney1 - nMoney1 > 0)
- {
- KSystemMessage sMsg;
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- sprintf(sMsg.szMessage, MSG_EARN_MONEY, pMoney->m_nMoney1 - nMoney1);
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
- m_ItemList.SetMoney(pMoney->m_nMoney1, pMoney->m_nMoney2, pMoney->m_nMoney3);
- }
- }
- #endif
- #ifndef _SERVER
- //---------------------------------------------------------------------
- // 功能:收到服务器通知有人申请交易
- //---------------------------------------------------------------------
- void KPlayer::s2cTradeApplyStart(BYTE* pMsg)
- {
- if (!pMsg)
- return;
- TRADE_APPLY_START_SYNC *pApply = (TRADE_APPLY_START_SYNC*)pMsg;
- int nNpcIdx;
- nNpcIdx = NpcSet.SearchID(pApply->m_dwNpcId);
- if (nNpcIdx == 0)
- return;
-
- KSystemMessage sMsg;
- KUiPlayerItem sPlayer;
-
- strcpy(sPlayer.Name, Npc[nNpcIdx].Name);
- sPlayer.nIndex = pApply->m_nDestIdx;
- sPlayer.uId = pApply->m_dwNpcId;
- sPlayer.nData = 0;
-
- sprintf(sMsg.szMessage, MSG_TRADE_GET_APPLY, Npc[nNpcIdx].Name);
- sMsg.eType = SMT_SYSTEM;
- sMsg.byConfirmType = SMCT_UI_TRADE;
- sMsg.byPriority = 3;
- sMsg.byParamSize = sizeof(KUiPlayerItem);
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
- }
- #endif
- #ifndef _SERVER
- void KPlayer::s2cTradeMoneySync(BYTE* pMsg)
- {
- TRADE_MONEY_SYNC *pMoney = (TRADE_MONEY_SYNC*)pMsg;
-
- m_ItemList.SetRoomMoney(room_trade1, pMoney->m_nMoney);
-
- // 通知界面
- KUiObjAtRegion sMoney;
- sMoney.Obj.uGenre = CGOG_MONEY;
- sMoney.Obj.uId = pMoney->m_nMoney;
- CoreDataChanged(GDCNI_TRADE_DESIRE_ITEM, (unsigned int)&sMoney, 0);
- }
- #endif
- #ifndef _SERVER
- //---------------------------------------------------------------------
- // 功能:收到服务器通知交易完成或取消
- //---------------------------------------------------------------------
- void KPlayer::s2cTradeDecision(BYTE* pMsg)
- {
- TRADE_DECISION_SYNC *pSync = (TRADE_DECISION_SYNC*)pMsg;
- if (pSync->m_btDecision == 1) // 完成交易
- {
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TRADE_SUCCESS, m_cTrade.m_szDestName);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
-
- // 交给ItemList.Remove来清除 modify by spe 03/06/14
- //m_ItemList.ClearRoom(room_trade);
- m_ItemList.RemoveAllInOneRoom(room_trade1);
- //m_ItemList.ClearRoom(room_trade1);
- m_ItemList.ClearRoom(room_tradeback);
- this->m_cTrade.Release();
- m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
-
- // 通知界面交易结束
- CoreDataChanged(GDCNI_TRADE_END, 0, 0);
-
- m_ItemList.MenuSetMouseItem();
- }
- else if (pSync->m_btDecision == 0) // 取消交易
- {
- if ( !CheckTrading() )
- return;
-
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TRADE_FAIL, m_cTrade.m_szDestName);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
-
- // 取消交易的数据恢复
- m_ItemList.RecoverTrade();
- m_ItemList.SetMoney(m_cTrade.m_nBackEquipMoney, m_cTrade.m_nBackRepositoryMoney, 0);
- m_ItemList.ClearRoom(room_trade);
- m_ItemList.RemoveAllInOneRoom(room_trade1);
- // m_ItemList.ClearRoom(room_trade1);
- m_ItemList.ClearRoom(room_tradeback);
- m_cTrade.Release();
- m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
-
- // 通知界面交易结束
- CoreDataChanged(GDCNI_TRADE_END, 0, 0);
- // 更新物品面版
- CoreDataChanged(GDCNI_CONTAINER_OBJECT_CHANGED, UOC_ITEM_TAKE_WITH, 0);
-
- m_ItemList.MenuSetMouseItem();
- }
- }
- #endif
- #ifndef _SERVER
- void KPlayer::SyncCurPlayer(BYTE* pMsg)
- {
- m_ItemList.RemoveAll();
-
- CURPLAYER_SYNC* PlaySync = (CURPLAYER_SYNC *)pMsg;
- this->m_nIndex = NpcSet.SearchID(PlaySync->m_dwID);
- this->m_dwID = g_FileName2Id(Npc[m_nIndex].Name);
-
- Npc[m_nIndex].m_Kind = kind_player;
- Npc[m_nIndex].m_Level = (DWORD)PlaySync->m_btLevel;
- Npc[m_nIndex].m_nSex = PlaySync->m_btSex;
- Npc[m_nIndex].m_Series = PlaySync->m_btSeries;
- Npc[m_nIndex].SetPlayerIdx(CLIENT_PLAYER_INDEX);
-
- m_nAttributePoint = PlaySync->m_wAttributePoint;
- m_nSkillPoint = PlaySync->m_wSkillPoint;
- m_nStrength = PlaySync->m_wStrength;
- m_nDexterity = PlaySync->m_wDexterity;
- m_nVitality = PlaySync->m_wVitality;
- m_nEngergy = PlaySync->m_wEngergy;
- m_nLucky = PlaySync->m_wLucky;
-
- m_nCurStrength = m_nStrength;
- m_nCurDexterity = m_nDexterity;
- m_nCurVitality = m_nVitality;
- m_nCurEngergy = m_nEngergy;
- m_nCurLucky = m_nLucky;
- SetFirstDamage();
- SetBaseAttackRating();
- SetBaseDefence();
- Npc[m_nIndex].m_ActionScriptID = 0;
- Npc[m_nIndex].m_TrapScriptID = 0;
- m_nExp = PlaySync->m_nExp;
- m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(PlaySync->m_btLevel);
- m_dwLeadExp = PlaySync->m_dwLeadExp;
- m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(m_dwLeadExp);
- m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel);
-
- m_cFaction.m_nCurFaction = (char)PlaySync->m_btCurFaction;
- m_cFaction.m_nFirstAddFaction = (char)PlaySync->m_btFirstFaction;
- m_cFaction.m_nAddTimes = PlaySync->m_nFactionAddTimes;
-
- m_nWorldStat = (int)PlaySync->m_wWorldStat;
- m_nSectStat = (int)PlaySync->m_wSectStat;
- m_ItemList.Init(CLIENT_PLAYER_INDEX);
- m_ItemList.SetMoney(PlaySync->m_nMoney1, PlaySync->m_nMoney2, 0);
-
- Npc[m_nIndex].m_LifeMax = PlaySync->m_wLifeMax;
- Npc[m_nIndex].m_ManaMax = PlaySync->m_wManaMax;
- Npc[m_nIndex].m_StaminaMax = PlaySync->m_wStaminaMax;
- Npc[m_nIndex].m_LifeReplenish = PLAYER_LIFE_REPLENISH;
- Npc[m_nIndex].m_ManaReplenish = PLAYER_MANA_REPLENISH;
- Npc[m_nIndex].m_StaminaGain = PLAYER_STAMINA_GAIN;
- Npc[m_nIndex].m_StaminaLoss = PLAYER_STAMINA_LOSS;
-
- SetBaseResistData();
- SetBaseSpeedAndRadius();
-
- Npc[m_nIndex].RestoreNpcBaseInfo();
-
- m_BuyInfo.Clear();
- m_cMenuState.Release();
- m_cChat.Release();
- memset(m_szTaskAnswerFun, 0, sizeof(m_szTaskAnswerFun));
- m_nAvailableAnswerNum = 0;
-
- Npc[m_nIndex].m_Experience = 0;
- memset(Npc[m_nIndex].m_szChatBuffer, 0, sizeof(Npc[m_nIndex].m_szChatBuffer));
- Npc[m_nIndex].m_nCurChatTime = 0;
-
- m_RunStatus = 1;
- m_nLeftSkillID = 0;
- m_nLeftSkillLevel = 0;
- m_nRightSkillID = 0;
- m_nRightSkillLevel = 0;
- m_nPeapleIdx = 0;
- m_nObjectIdx = 0;
- m_MouseDown[0] = 0;
- m_MouseDown[1] = 0;
-
- Npc[m_nIndex].m_SyncSignal = 0;
- //Npc[m_nIndex].RestoreLiveData();
- // SubWorld[0].AddPlayer(Npc[m_nIndex].m_RegionIndex, 0);//m_Region[Npc[m_nIndex].m_RegionIndex].AddPlayer(0);// m_WorldMessage.Send(GWM_PLAYER_ADD, Npc[m_nIndex].m_RegionIndex, 0);
- }
- #endif
- BOOL KPlayer::CheckTrading()
- {
- return (m_cMenuState.m_nState == PLAYER_MENU_STATE_TRADING);
- }
- void KPlayer::SetFirstDamage()
- {
- int nDamageBase;
-
-
- nDamageBase = m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE + 1;
-
- Npc[m_nIndex].m_PhysicsDamage.nValue[0] = nDamageBase;
- Npc[m_nIndex].m_PhysicsDamage.nValue[2] = nDamageBase;
- Npc[m_nIndex].m_PhysicsDamage.nValue[1] = 0;
-
- Npc[m_nIndex].m_CurrentFireDamage.nValue[0] = 0;
- Npc[m_nIndex].m_CurrentFireDamage.nValue[1] = 0;
- Npc[m_nIndex].m_CurrentFireDamage.nValue[2] = 0;
-
- Npc[m_nIndex].m_CurrentColdDamage.nValue[0] = 0;
- Npc[m_nIndex].m_CurrentColdDamage.nValue[1] = 0;
- Npc[m_nIndex].m_CurrentColdDamage.nValue[2] = 0;
-
- Npc[m_nIndex].m_CurrentLightDamage.nValue[0] = 0;
- Npc[m_nIndex].m_CurrentLightDamage.nValue[1] = 0;
- Npc[m_nIndex].m_CurrentLightDamage.nValue[2] = 0;
-
- Npc[m_nIndex].m_CurrentPoisonDamage.nValue[0] = 0;
- Npc[m_nIndex].m_CurrentPoisonDamage.nValue[1] = 0;
- Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2] = 0;
-
- }
- void KPlayer::SetBaseAttackRating()
- {
- Npc[m_nIndex].m_AttackRating = m_nDexterity * 4 - 28;
- }
- void KPlayer::SetBaseDefence()
- {
- Npc[m_nIndex].m_Defend = m_nDexterity >> 2;
- }
- void KPlayer::SetBaseResistData()
- {
- Npc[m_nIndex].m_FireResist = PlayerSet.m_cLevelAdd.GetFireResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_ColdResist = PlayerSet.m_cLevelAdd.GetColdResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_PoisonResist = PlayerSet.m_cLevelAdd.GetPoisonResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_LightResist = PlayerSet.m_cLevelAdd.GetLightResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_PhysicsResist = PlayerSet.m_cLevelAdd.GetPhysicsResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
- Npc[m_nIndex].m_FireResistMax = BASE_FIRE_RESIST_MAX;
- Npc[m_nIndex].m_ColdResistMax = BASE_COLD_RESIST_MAX;
- Npc[m_nIndex].m_PoisonResistMax = BASE_POISON_RESIST_MAX;
- Npc[m_nIndex].m_LightResistMax = BASE_LIGHT_RESIST_MAX;
- Npc[m_nIndex].m_PhysicsResistMax = BASE_PHYSICS_RESIST_MAX;
- }
- void KPlayer::SetBaseSpeedAndRadius()
- {
- Npc[m_nIndex].m_WalkSpeed = BASE_WALK_SPEED;
- Npc[m_nIndex].m_RunSpeed = BASE_RUN_SPEED;
- Npc[m_nIndex].m_AttackSpeed = BASE_ATTACK_SPEED;
- Npc[m_nIndex].m_CastSpeed = BASE_CAST_SPEED;
- Npc[m_nIndex].m_VisionRadius = BASE_VISION_RADIUS;
- Npc[m_nIndex].m_HitRecover = BASE_HIT_RECOVER;
- }
- #ifndef _SERVER
- //客户端版本
- void KPlayer::DialogNpc(int nIndex)
- {
- if (nIndex > 0 && Npc[nIndex].m_Index > 0)
- {
- if (Npc[nIndex].ActionScript[0])
- {
- ExecuteScript(Npc[nIndex].m_ActionScriptID,"main","");
- }
- else
- {
- PLAYER_DIALOG_NPC_COMMAND DialogNpcCmd;
- DialogNpcCmd.nNpcId = Npc[nIndex].m_dwID;
- DialogNpcCmd.ProtocolType = c2s_dialognpc;
- if (g_pClient)
- g_pClient->SendPackToServer(&DialogNpcCmd, sizeof(PLAYER_DIALOG_NPC_COMMAND));
-
- }
- }
- }
- #endif
- #ifndef _SERVER
- void KPlayer::CheckObject(int nIdx)
- {
- /* enum // 物件类型
- {
- Obj_Kind_MapObj = 0, // 地图物件,主要用于地图动画
- Obj_Kind_Body, // npc 的尸体
- Obj_Kind_Box, // 宝箱
- Obj_Kind_Item, // 掉在地上的装备
- Obj_Kind_Money, // 掉在地上的钱
- Obj_Kind_LoopSound, // 循环音效
- Obj_Kind_RandSound, // 随机音效
- Obj_Kind_Light, // 光源(3D模式中发光的东西)
- Obj_Kind_Door, // 门类
- Obj_Kind_Trap, // 陷阱
- Obj_Kind_Prop, // 小道具,可重生
- Obj_Kind_Num, // 物件的种类数
- };*/
-
- switch(Object[nIdx].m_nKind)
- {
- case Obj_Kind_Item:
- case Obj_Kind_Money:
- PickUpObj(nIdx);
- Npc[m_nIndex].m_nObjectIdx = 0;
- break;
- case Obj_Kind_Box:
- case Obj_Kind_Door:
- case Obj_Kind_Trap:
- case Obj_Kind_Prop:
- this->ObjMouseClick(nIdx);
- Npc[m_nIndex].m_nObjectIdx = 0;
- break;
- default:
- break;
- }
- m_nObjectIdx = 0;
- m_nPickObjectIdx = 0;
- }
- #endif
- #ifndef _SERVER
- void KPlayer::DrawSelectInfo()
- {
- if (m_nIndex <= 0)
- return;
-
- if (m_nPeapleIdx)
- {
- // Npc[m_nPeapleIdx].DrawBorder();
- if (Npc[m_nPeapleIdx].m_Kind == kind_player)
- {
- if (!NpcSet.CheckShowName())
- {
- Npc[m_nPeapleIdx].PaintInfo(Npc[m_nPeapleIdx].GetNpcPate(), true);
- }
- }
- else if (Npc[m_nPeapleIdx].m_Kind == kind_dialoger)
- {
- if (!NpcSet.CheckShowName())
- {
- Npc[m_nPeapleIdx].PaintInfo(Npc[m_nPeapleIdx].GetNpcPate(), true);
- }
- }
- else
- {
- Npc[m_nPeapleIdx].DrawBlood();
- }
-
- return;
- }
- if (m_nObjectIdx)
- {
- if (!ObjSet.CheckShowName())
- Object[m_nObjectIdx].DrawInfo();
- // Object[m_nObjectIdx].DrawBorder();
- return;
- }
- }
- #endif
- #ifndef _SERVER
- void KPlayer::GetEchoDamage(int* nMin, int* nMax, int nType)
- {
- int nSkillId;
- *nMin = 0;
- *nMax = 0;
-
- if (m_nIndex <= 0 || m_nIndex >= MAX_NPC
- || nType < 0 || nType > 1
- || NULL == nMin || NULL == nMax)
- return;
-
- nSkillId = (0 == nType)?m_nLeftSkillID:m_nRightSkillID;
- int nLevel = Npc[m_nIndex].m_SkillList.GetCurrentLevel(nSkillId);
-
- if (nSkillId <= 0 ||nLevel <= 0 || nLevel >= MAX_SKILLLEVEL)
- return;
-
- KMagicAttrib* pMagicData = NULL;
-
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nSkillId, nLevel);
- if (!pOrdinSkill)
- return ;
- switch(pOrdinSkill->GetSkillStyle())
- {
- case SKILL_SS_Missles: // 子弹类 本技能用于发送子弹类
- case SKILL_SS_Melee:
- case SKILL_SS_InitiativeNpcState: // 主动类 本技能用于改变当前Npc的主动状态
- case SKILL_SS_PassivityNpcState: // 被动类 本技能用于改变Npc的被动状态
- {
- }
- break;
- default:
- return;
- }
-
- BOOL bIsPhysical = pOrdinSkill->IsPhysical();
-
- pMagicData = pOrdinSkill->GetDamageAttribs();
-
- if (!pMagicData)
- return;
-
-
-
- int nMinNpcDamage = Npc[m_nIndex].m_PhysicsDamage.nValue[0] + Npc[m_nIndex].m_CurrentAddPhysicsDamage;
- int nMaxNpcDamage = Npc[m_nIndex].m_PhysicsDamage.nValue[2] + Npc[m_nIndex].m_CurrentAddPhysicsDamage;
- // Skip attackrating
- pMagicData++;
- // Skip ignoredefense
- pMagicData++;
- // Calc physics damage
- if (magic_physicsenhance_p == pMagicData->nAttribType)
- {
- *nMin += nMinNpcDamage * (100 + pMagicData->nValue[0]) / 100;
- *nMax += nMaxNpcDamage * (100 + pMagicData->nValue[0]) / 100;
-
- int nEnhance;
- if (equip_meleeweapon == m_ItemList.GetWeaponType())
- {
- nEnhance = Npc[m_nIndex].m_CurrentMeleeEnhance[m_ItemList.GetWeaponParticular()];
- }
- else if (equip_rangeweapon == m_ItemList.GetWeaponType())
- {
- nEnhance = Npc[m_nIndex].m_CurrentRangeEnhance;
- }
- else
- {
- nEnhance = Npc[m_nIndex].m_CurrentHandEnhance;
- }
- *nMin += nMinNpcDamage * nEnhance / 100;
- *nMax += nMaxNpcDamage * nEnhance / 100;
- }
- else if (magic_physicsdamage_v == pMagicData->nAttribType)
- {
- *nMin += pMagicData->nValue[0];
- *nMax += pMagicData->nValue[2];
- }
- pMagicData++;
- // Calc cold damage
- if (magic_colddamage_v == pMagicData->nAttribType)
- {
- *nMin += pMagicData->nValue[0];
- *nMax += pMagicData->nValue[2];
- }
- if (bIsPhysical)
- {
- *nMin += Npc[m_nIndex].m_CurrentColdDamage.nValue[0];
- *nMax += Npc[m_nIndex].m_CurrentColdDamage.nValue[2];
- }
- pMagicData++;
- // Calc fire damage
- if (magic_firedamage_v == pMagicData->nAttribType)
- {
- *nMin += pMagicData->nValue[0];
- *nMax += pMagicData->nValue[2];
- }
- if (bIsPhysical)
- {
- *nMin += Npc[m_nIndex].m_CurrentFireDamage.nValue[0];
- *nMax += Npc[m_nIndex].m_CurrentFireDamage.nValue[2];
- }
- pMagicData++;
- // Calc lighting damage
- if (magic_lightingdamage_v == pMagicData->nAttribType)
- {
- *nMin += pMagicData->nValue[0];
- *nMax += pMagicData->nValue[2];
- }
- if (bIsPhysical)
- {
- *nMin += Npc[m_nIndex].m_CurrentLightDamage.nValue[0];
- *nMax += Npc[m_nIndex].m_CurrentLightDamage.nValue[2];
- }
- pMagicData++;
- // Calc poison damage
- if (magic_poisondamage_v == pMagicData->nAttribType)
- {
- if (pMagicData->nValue[2] > 0)
- {
- int nPoisonDamage = (pMagicData->nValue[0] * pMagicData->nValue[1] / pMagicData->nValue[2]);
- *nMin += nPoisonDamage;
- *nMax += nPoisonDamage;
- }
- }
- if (bIsPhysical)
- {
- if (Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2] > 0)
- {
- int nPoisonDamage = (Npc[m_nIndex].m_CurrentPoisonDamage.nValue[0]
- * Npc[m_nIndex].m_CurrentPoisonDamage.nValue[1]
- / Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2]);
- *nMin += nPoisonDamage;
- *nMax += nPoisonDamage;
- }
- }
- pMagicData++;
- // Calc magic damage
- if (magic_magicdamage_v == pMagicData->nAttribType)
- {
- *nMin += pMagicData->nValue[0];
- *nMax += pMagicData->nValue[2];
- }
- }
- #endif
- void KPlayer::SetNpcDamageAttrib()
- {
- SetNpcPhysicsDamage();
- }
- #ifdef _SERVER
- void KPlayer::TobeExchangeServer(DWORD dwMapID, int nX, int nY)
- {
- if (!m_dwID || m_nNetConnectIdx == -1)
- return;
-
- m_sExchangePos.m_dwMapID = dwMapID;
- m_sExchangePos.m_nX = nX;
- m_sExchangePos.m_nY = nY;
- m_bExchangeServer = TRUE;
- }
- #endif
- /*
- #ifdef _SERVER
- void KPlayer::UpdateEnterGamePos(DWORD dwSubWorldID, int nX, int nY, int nFightMode)
- {
- TRoleData* pData = (TRoleData *)&m_SaveBuffer;
- pData->BaseInfo.cFightMode = nFightMode;
- pData->BaseInfo.cUseRevive = 0;
- pData->BaseInfo.ientergameid = dwSubWorldID;
- pData->BaseInfo.ientergamex = nX;
- pData->BaseInfo.ientergamey = nY;
- }
- #endif
- */
- #ifdef _SERVER
- BOOL KPlayer::IsExchangingServer()
- {
- return m_bExchangeServer;
- }
- #endif
- #ifdef _SERVER
- void KPlayer::SetLastNetOperationTime(int nTime)
- {
- if (m_nNetConnectIdx == -1 || m_dwID == 0 || m_nIndex <= 0)
- return;
-
- m_nLastNetOperationTime = nTime;
- if (m_bSleepMode)
- {
- m_bSleepMode = FALSE;
- NPC_SLEEP_SYNC SleepSync;
- SleepSync.ProtocolType = s2c_npcsleepmode;
- SleepSync.bSleep = m_bSleepMode;
- SleepSync.NpcID = Npc[m_nIndex].m_dwID;
- Npc[m_nIndex].SendDataToNearRegion(&SleepSync, sizeof(NPC_SLEEP_SYNC));
- }
- }
- #endif
- #ifdef _SERVER
- BOOL KPlayer::CreateTong(int nCamp, char *lpszTongName)
- {
- return this->m_cTong.Create(nCamp, lpszTongName);
- }
- #endif
- #ifdef _SERVER
- void KPlayer::RepairItem(DWORD dwItemID)
- {
- int nIdx = m_ItemList.SearchID(dwItemID);
- int nCost = Item[nIdx].GetRepairPrice();
- if (!nCost)
- return;
- int nMaxDur = Item[nIdx].GetMaxDurability();
- int nDur = Item[nIdx].GetDurability();
- if (Pay(nCost) && m_nNetConnectIdx >= 0)
- {
- Item[nIdx].SetDurability(nMaxDur);
- ITEM_DURABILITY_CHANGE IDC;
- IDC.ProtocolType = s2c_itemdurabilitychange;
- IDC.dwItemID = dwItemID;
- IDC.nChange = nMaxDur - nDur;
- if (g_pServer)
- g_pServer->PackDataToClient(m_nNetConnectIdx, &IDC, sizeof(ITEM_DURABILITY_CHANGE));
- }
- }
- #endif
- #ifdef _SERVER
- void KPlayer::SetExtPoint(int nPoint, int nChangePoint)
- {
- m_nExtPoint = nPoint;
- m_nChangeExtPoint = nChangePoint;
- }
- int KPlayer::GetExtPoint()
- {
- return m_nExtPoint;
- }
- BOOL KPlayer::PayExtPoint(int nPoint)
- {
- if (m_nExtPoint < nPoint)
- return FALSE;
- m_nExtPoint -= nPoint;
- m_nChangeExtPoint += nPoint;
- return TRUE;
- }
- int KPlayer::GetExtPointChanged()
- {
- return m_nChangeExtPoint;
- }
- #endif
- // 物品相应的操作:
- // 获得物品:1、从地上拣物品 2、脚本控制直接给 3、交易 4、player 之间赠
- // 送(通过交易实现)
- // 客户端鼠标点在物件上,然后客户端通过物件得出物品id、应该出现在装备栏或者
- // 物品栏的位置或者跟随鼠标的计算,把计算结果发给服务器;服务器收到后首先判
- // 断玩家与物品的位置关系,然后检查客户端的计算结果是否正确,然后进行相应的
- // 处理,把处理结果发给客户端
- // 物品的位置调整:客户端处理好物品来源位置、鼠标上物品目的位置,然后发给服务器,
- // 服务器确认后通知客户端最终确定的操作(如果成功,把协议原样发回去);如果有数
- // 值等其他变化,另外通知客户端;
- // 使用物品:1、吃药 2、装备(鼠标右键点击)
- // 客户端向服务器端申请吃什么位置的药,同时客户端的相应数值先作相应变化,服
- // 务器收到客户端申请后,处理完相应数据,通过player同步的方式通知客户端数据
- // 的变化;
- // 装备:鼠标右键点在一个装备上,自动处理装备上、卸下的位置信息,发给服务器,
- // 服务器处理完后原样发回来;
- // 交易的处理还没有