KPlayer.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:187k
- #include "KCore.h"
- #ifndef WM_MOUSEHOVER
- #define WM_MOUSEHOVER 0x02A1
- #endif
- #include "KEngine.h"
- #ifdef _SERVER
- //#include "KNetServer.h"
- //#include "../MultiServer/Heaven/Interface/iServer.h"
- #else
- //#include "KNetClient.h"
- #include "../../Headers/IClient.h"
- #include "Scene/KScenePlaceC.h"
- #include "KIme.h"
- #endif
- #include "KNpc.h"
- #include "KObj.h"
- #include "KNpcSet.h"
- #include "KSubWorld.h"
- #include "KPlayer.h"
- #include "LuaFuns.h"
- #include "KSortScript.h"
- #include "KScriptValueSet.h"
- #include "KObjSet.h"
- #include "KSkills.h"
- #include "KPlayerSet.h"
- #include "KSubWorldSet.h"
- #include "KFile.h"
- #include "GameDataDef.h"
- #include "KBuySell.h"
- //#include "MyAssert.h"
- #include "MsgGenreDef.h"
- #include "KItemSet.h"
- #include "KTaskFuns.h"
- #include "Text.h"
- #ifdef _SERVER
- #ifndef _STANDALONE
- #include "../../../lib/S3DBInterface.h"
- #else
- #include "S3DBInterface.h"
- #endif
- #else
- #include "CoreShell.h"
- #endif
- extern int LuaGetNpcTalk(Lua_State *L);
- #define defPLAYER_LOGIN_TIMEOUT 10 * 20// 10 sec
- #define defPLAYER_SAVE_TIMEOUT 30 * 20
- #define PLAYER_LEVEL_1_EXP 48
- #define PLAYER_LEVEL_ADD_ATTRIBUTE 5
- #define PLAYER_LEVEL_ADD_SKILL 1
- #define PLAYER_SHARE_EXP_DISTANCE 768
- #define PLAYER_TEAM_EXP_ADD 50
- #define MAX_APPLY_TEAM_TIME 500
- #define BASE_WALK_SPEED 5
- #define BASE_RUN_SPEED 10
- #define BASE_FIRE_RESIST_MAX 75
- #define BASE_COLD_RESIST_MAX 75
- #define BASE_POISON_RESIST_MAX 75
- #define BASE_LIGHT_RESIST_MAX 75
- #define BASE_PHYSICS_RESIST_MAX 75
- #define BASE_ATTACK_SPEED 20
- #define BASE_CAST_SPEED 20
- #define BASE_VISION_RADIUS 120
- #define BASE_HIT_RECOVER 6
- #define TOWN_PORTAL_TIME 1800
- KPlayer Player[MAX_PLAYER];
- int g_nLastNetMsgLoop;
- //-------------------------------------------------------------------------
- // 功能:构造函数
- //-------------------------------------------------------------------------
- KPlayer::KPlayer()
- {
- Release();
- }
- //-------------------------------------------------------------------------
- // 功能:析构函数
- //-------------------------------------------------------------------------
- KPlayer::~KPlayer()
- {
- Release();
- }
- //-------------------------------------------------------------------------
- // 功能:清空
- //-------------------------------------------------------------------------
- void KPlayer::Release()
- {
- #ifndef _SERVER
- m_RunStatus = 0;
- m_dwNextLevelLeadExp = 0;
- m_nLeftSkillID = 0;
- m_nLeftSkillLevel = 0;
- m_nRightSkillID = 0;
- m_nRightSkillLevel = 0;
- m_nSendMoveFrames = defMAX_PLAYER_SEND_MOVE_FRAME;
- m_MouseDown[0] = FALSE;
- m_MouseDown[1] = FALSE;
- #endif
- m_dwID = 0;
- m_nIndex = 0;
- m_nNetConnectIdx = -1;
- m_cMenuState.Release();
- m_cTrade.Release();
- m_nAttributePoint = 0;
- m_nSkillPoint = 0;
-
- m_nStrength = 0;
- m_nDexterity = 0;
- m_nVitality = 0;
- m_nEngergy = 0;
- m_nLucky = 0;
- m_nCurStrength = 0;
- m_nCurDexterity = 0;
- m_nCurVitality = 0;
- m_nCurEngergy = 0;
- m_nCurLucky = 0;
- m_btChatSpecialChannel = 0;
-
- m_nExp = 0;
- m_nNextLevelExp = PLAYER_LEVEL_1_EXP;
- m_bExchangeServer = FALSE;
-
- m_dwLeadExp = 0;
- m_dwLeadLevel = 1;
-
- m_nPeapleIdx = 0;
- m_nObjectIdx = 0;
- m_bWaitingPlayerFeedBack = false;
- m_btTryExecuteScriptTimes = 0; //
-
-
- #ifdef _SERVER
- m_bUseReviveIdWhenLogin = 0;
- m_dwDeathScriptId = 0;
-
- m_sLoginRevivalPos.m_nSubWorldID = 0;
- m_sLoginRevivalPos.m_nMpsX = 0;
- m_sLoginRevivalPos.m_nMpsY = 0;
-
- m_sDeathRevivalPos.m_nSubWorldID = 0;
- m_sDeathRevivalPos.m_nMpsX = 0;
- m_sDeathRevivalPos.m_nMpsY = 0;
-
- m_sPortalPos.m_nSubWorldId = 0;
- m_sPortalPos.m_nTime = 0;
- m_sPortalPos.m_nMpsX = 0;
- m_sPortalPos.m_nMpsY = 0;
-
- m_pLastScriptCacheNode = NULL;
- m_dwLoginTime = -1;
- // m_uLastPingTime = -1;
- m_bFinishLoading = FALSE;
- m_uMustSave = SAVE_IDLE;
- m_bIsQuiting = FALSE;
- m_TimerTask.SetOwner(this);
- m_bSleepMode = FALSE;
- m_nLastNetOperationTime = 0;
- m_nPrePayMoney = 0;
- m_nForbiddenFlag = 0;
- m_nExtPoint = 0;
- m_nChangeExtPoint = 0;
- // ZeroMemory(m_SaveBuffer, sizeof(m_SaveBuffer));
- #endif
- }
- //-------------------------------------------------------------------------
- // 功能:设定 m_nPlayerIndex (本函数只允许在PlayerSet的Init中调用)
- //-------------------------------------------------------------------------
- void KPlayer::SetPlayerIndex(int nNo)
- {
- if (nNo < 0)
- m_nPlayerIndex = 0;
- else
- m_nPlayerIndex = nNo;
- }
- //-------------------------------------------------------------------------
- // 功能:获得本实例在 Player 数组中的位置
- //-------------------------------------------------------------------------
- int KPlayer::GetPlayerIndex()
- {
- return m_nPlayerIndex;
- }
- //-------------------------------------------------------------------------
- // 功能:玩家每次游戏循环都需要处理的东西
- //-------------------------------------------------------------------------
- void KPlayer::Active()
- {
- #ifdef _SERVER
- if (m_nNetConnectIdx == -1 || m_bExchangeServer)
- return;
-
- //时间任务的处理
- m_TimerTask.Activate(g_PlayerTimerCallBackFun);
- this->SendCurNormalSyncData();
-
- this->m_cChat.TimerAdd();
-
- // 仇杀倒计时
- this->m_cPK.Active();
- #define defMAX_SLEEP_TIME 3600
- if (Npc[m_nIndex].m_FightMode == 0 && m_bSleepMode == FALSE && g_SubWorldSet.GetGameTime() - m_nLastNetOperationTime > defMAX_SLEEP_TIME)
- {
- NPC_SLEEP_SYNC SleepSync;
- SleepSync.ProtocolType = s2c_npcsleepmode;
- SleepSync.bSleep = 1;
- SleepSync.NpcID = Npc[m_nIndex].m_dwID;
- Npc[m_nIndex].SendDataToNearRegion(&SleepSync, sizeof(NPC_SLEEP_SYNC));
- m_bSleepMode = TRUE;
- }
- #else
- // 队伍申请人的处理
- if ( !m_cTeam.m_nFlag )
- {
- if (m_cTeam.m_nApplyCaptainID > 0)
- {
- if ( m_cTeam.m_dwApplyTimer == 0 )
- {
- m_cTeam.m_nApplyCaptainID = 0;
-
- }
- else
- {
- m_cTeam.m_dwApplyTimer--;
- if ( !NpcSet.SearchID(m_cTeam.m_nApplyCaptainID) )
- {
- m_cTeam.m_nApplyCaptainID = 0;
- m_cTeam.m_dwApplyTimer = 0;
- }
- }
- }
- }
- // 队长的处理
- else if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
- {
- for (int i = 0; i < MAX_TEAM_APPLY_LIST; i++)
- {
- if (m_cTeam.m_sApplyList[i].m_dwNpcID > 0)
- {
- if (m_cTeam.m_sApplyList[i].m_dwTimer == 0)
- {
- m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
- m_cTeam.UpdateInterface();
- }
- else
- {
- m_cTeam.m_sApplyList[i].m_dwTimer--;
- if ( !Npc[this->m_nIndex].SearchAroundID(m_cTeam.m_sApplyList[i].m_dwNpcID) )
- {
- m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
- m_cTeam.m_sApplyList[i].m_dwTimer = 0;
- m_cTeam.UpdateInterface();
- }
- }
- }
- }
- }
-
- m_nSendMoveFrames++;
-
- // 仇杀倒计时
- this->m_cPK.Active();
-
- #endif
- }
- void KPlayer::ProcessMsg(KWorldMsgNode *lpMsg)
- {
- switch (lpMsg->m_dwMsgType)
- {
- case GWM_PLAYER_SKILL:
- break;
- case GWM_PLAYER_RUNTO:
- break;
- case GWM_PLAYER_WALKTO:
- break;
- case GWM_PLAYER_JUMPTO:
- break;
- default:
- break;
- }
- }
- #ifndef _SERVER
- void KPlayer::ProcessInputMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch(uMsg)
- {
- case WM_MOUSEMOVE:
- case WM_MOUSEHOVER:
- if (wParam & MK_LBUTTON)
- OnButtonMove(LOWORD(lParam), HIWORD(lParam),
- (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_left);
- else if (wParam & MK_RBUTTON)
- OnButtonMove(LOWORD(lParam), HIWORD(lParam),
- (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_right);
- else
- OnMouseMove(LOWORD(lParam), HIWORD(lParam));
- break;
-
- case WM_LBUTTONUP:
- OnButtonUp(LOWORD(lParam), HIWORD(lParam), button_left);
- break;
-
- case WM_LBUTTONDOWN:
- OnButtonDown(LOWORD(lParam), HIWORD(lParam),
- (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_left);
- break;
-
- case WM_RBUTTONUP:
- OnButtonUp(LOWORD(lParam), HIWORD(lParam), button_right);
- break;
-
- case WM_RBUTTONDOWN:
- OnButtonDown(LOWORD(lParam), HIWORD(lParam),
- (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_right);
- break;
- }
- }
- void KPlayer::OnButtonDown(int x,int y, int Key, MOUSE_BUTTON nButton)
- {
- m_MouseDown[(int)nButton] = TRUE;
-
- FindSelectNpc(x, y, relation_all);
- FindSelectObject(x, y);
- // Npc[m_nIndex].m_nPeopleIdx = m_nPeapleIdx;
- ProcessMouse(x, y, Key, nButton);
- }
- void KPlayer::OnButtonMove(int x,int y,int Key, MOUSE_BUTTON nButton)
- {
- if (m_MouseDown[(int)nButton])
- {
- ProcessMouse(x, y, Key, nButton);
- }
- }
- void KPlayer::OnButtonUp(int x,int y,MOUSE_BUTTON nButton)
- {
- m_MouseDown[(int)nButton] = 0;
- }
- void KPlayer::OnMouseMove(int x,int y)
- {
- m_nPeapleIdx = 0;
- m_nObjectIdx = 0;
- FindSelectNpc(x, y, relation_all);
- FindSelectObject(x, y);
- if (m_nPeapleIdx)
- {
- if (Npc[m_nPeapleIdx].m_Kind == kind_dialoger)
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_DIALOG);
- else if (NpcSet.GetRelation(m_nIndex, m_nPeapleIdx) == relation_enemy)
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_FIGHT);
- else
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_NORMAL);
- }
- else if (m_nObjectIdx)
- {
- if (Object[m_nObjectIdx].m_nKind == Obj_Kind_MapObj)
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_DIALOG);
- else if (Object[m_nObjectIdx].m_nKind == Obj_Kind_Item || Object[m_nObjectIdx].m_nKind == Obj_Kind_Money)
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_PICK);
- else if (Object[m_nObjectIdx].m_nKind == Obj_Kind_Prop)
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_USE);
- }
- else
- CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_NORMAL);
- }
- void KPlayer::ProcessMouse(int x, int y, int Key, MOUSE_BUTTON nButton)
- {
- if (CheckTrading())
- return;
-
- if (m_ItemList.m_Hand > 0)
- {
- if (nButton == button_left)
- {
- ThrowAwayItem();
- return;
- }
- }
-
- int nX = x;
- int nY = y;
- int nZ = 0;
- g_ScenePlace.ViewPortCoordToSpaceCoord(nX, nY, nZ);
-
- /* if (Key & MK_SHIFT)
- {
- Npc[m_nIndex].SendCommand(do_jump, nX, nY);
- SendClientCmdJump(nX, nY);
- return;
- }*/
-
- if (Npc[m_nIndex].IsCanInput())
- {
- int nIdx = 0;
-
- if (nButton == button_right)
- {
- nIdx = Npc[m_nIndex].m_SkillList.FindSame(m_nRightSkillID);
- g_DebugLog("[skill]right");
- }
- else
- {
- nIdx = Npc[m_nIndex].m_SkillList.FindSame(m_nLeftSkillID);
- g_DebugLog("[skill]left");
- }
- Npc[m_nIndex].SetActiveSkill(nIdx);
- }
- else
- {
- g_DebugLog("[skill]return");
- Npc[m_nIndex].m_nPeopleIdx = 0;
- return;
- }
-
- if ((Key & MK_SHIFT) || (nButton == button_right))
- {
- if (Npc[m_nIndex].m_ActiveSkillID > 0)
- {
- ISkill * pISkill = (KSkill *) g_SkillManager.GetSkill(Npc[m_nIndex].m_ActiveSkillID, 1);
- if (!pISkill)
- return;
-
- if (pISkill->IsAura())
- return;
- int nAttackRange = pISkill->GetAttackRadius();
-
- int nTargetIdx = 0;
- // m_nPeapleIdx = 0;
- //按照Object / Enemy / Ally 的优先级找到需要打的对象id
-
-
- if (pISkill->IsTargetAlly())
- {
- FindSelectNpc(x, y, relation_ally);
- if (m_nPeapleIdx)
- {
- nTargetIdx = m_nPeapleIdx;
- }
- }
-
- if (pISkill->IsTargetEnemy())
- {
- FindSelectNpc(x, y, relation_enemy);
- if (m_nPeapleIdx)
- {
- nTargetIdx = m_nPeapleIdx;
- }
- }
-
- if (pISkill->IsTargetObj())
- {
- FindSelectObject(x, y);
- if (m_nObjectIdx)
- {
- nTargetIdx = m_nObjectIdx;
- }
- }
- //如果技能必须指定对象,而当前位置无对象的话,直接退出
- if (pISkill->IsTargetOnly() && !nTargetIdx)
- {
- Npc[m_nIndex].m_nPeopleIdx = 0;
- m_nPeapleIdx = 0;
- return;
- }
-
- if (m_nIndex == nTargetIdx)
- {
- Npc[m_nIndex].m_nPeopleIdx = 0;
- m_nPeapleIdx = 0;
- return;
- }
-
- if ((!Npc[m_nIndex].m_SkillList.CanCast(Npc[m_nIndex].m_ActiveSkillID, SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_dwCurrentTime))
- ||
- (!Npc[m_nIndex].Cost(pISkill->GetSkillCostType() , pISkill->GetSkillCost(&Npc[m_nIndex]), TRUE))
- )
- {
- Npc[m_nIndex].m_nPeopleIdx = 0;
- m_nPeapleIdx = 0;
- return ;
- }
-
- //无对象,直接发坐标
- if (!nTargetIdx)
- {
- Npc[m_nIndex].SendCommand(do_skill, Npc[m_nIndex].m_ActiveSkillID, nX, nY);
- // Send to Server
- SendClientCmdSkill(Npc[m_nIndex].m_ActiveSkillID, nX, nY);
- }
- else
- {
- if (pISkill->IsTargetOnly())
- {
- int distance = NpcSet.GetDistance(m_nIndex , nTargetIdx);
- if (distance > pISkill->GetAttackRadius())
- {
- m_nPeapleIdx = nTargetIdx;
- return ;
- }
- }
- //
- if (m_nIndex == nTargetIdx && pISkill->GetSkillStyle() == SKILL_SS_Missles)
- return ;
- Npc[m_nIndex].SendCommand(do_skill, Npc[m_nIndex].m_ActiveSkillID, -1, nTargetIdx);
- // Send to Server
- SendClientCmdSkill(Npc[m_nIndex].m_ActiveSkillID, -1, Npc[nTargetIdx].m_dwID);
- }
- }
- Npc[m_nIndex].m_nPeopleIdx = 0;
- return;
- }
-
-
- if (Key == 0 )
- {
- int nRelation = NpcSet.GetRelation(m_nIndex, m_nPeapleIdx);
- if(nRelation == relation_enemy || nRelation == relation_dialog)
- {
- Npc[m_nIndex].m_nPeopleIdx = m_nPeapleIdx;
- }
-
- if (m_nSendMoveFrames >= defMAX_PLAYER_SEND_MOVE_FRAME)
- {
- m_nPickObjectIdx = m_nObjectIdx;
- Npc[m_nIndex].m_nObjectIdx = m_nPickObjectIdx;
- if (!m_RunStatus)
- {
- Npc[m_nIndex].SendCommand(do_walk, nX, nY);
- // Send to Server
- SendClientCmdWalk(nX, nY);
- }
- else
- {
- Npc[m_nIndex].SendCommand(do_run, nX, nY);
- // Send to Server
- SendClientCmdRun(nX, nY);
- }
- m_nSendMoveFrames = 0;
- }
- return;
- }
-
- /* if (Key & MK_ALT)
- {
- Npc[m_nIndex].SendCommand(do_jump, nX, nY);
- SendClientCmdJump(nX, nY);
- }*/
- }
- void KPlayer::Walk(int nDir, int nSpeed)
- {
- int nMapX = Npc[m_nIndex].m_MapX;
- int nMapY = Npc[m_nIndex].m_MapY;
- int nOffX = Npc[m_nIndex].m_OffX;
- int nOffY = Npc[m_nIndex].m_OffY;
- int nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
- int nRegion = Npc[m_nIndex].m_RegionIndex;
- int nX, nY;
-
- SubWorld[nSubWorld].Map2Mps(nRegion, nMapX, nMapY, nOffX, nOffY, &nX, &nY);
- SubWorld[nSubWorld].GetMps(&nX, &nY, nSpeed * 2, nDir);
-
- if (m_RunStatus)
- {
- Npc[m_nIndex].SendCommand(do_run, nX, nY);
- // Send to Server
- if ( !CheckTrading() )
- SendClientCmdRun(nX, nY);
- }
- else
- {
- Npc[m_nIndex].SendCommand(do_walk, nX, nY);
- // Send to Server
- if (!CheckTrading())
- SendClientCmdWalk(nX, nY);
- }
- }
- void KPlayer::TurnLeft()
- {
- if (Npc[m_nIndex].m_Doing != do_stand &&
- Npc[m_nIndex].m_Doing != do_sit)
- return;
-
- if (Npc[m_nIndex].m_Dir > 8)
- Npc[m_nIndex].m_Dir -= 8;
- else
- Npc[m_nIndex].m_Dir = MAX_NPC_DIR - 1;
- }
- void KPlayer::TurnRight()
- {
- if (Npc[m_nIndex].m_Doing != do_stand &&
- Npc[m_nIndex].m_Doing != do_sit)
- return;
-
- if (Npc[m_nIndex].m_Dir < MAX_NPC_DIR - 9)
- Npc[m_nIndex].m_Dir += 8;
- else
- Npc[m_nIndex].m_Dir = 0;
- }
- void KPlayer::TurnBack()
- {
- if (Npc[m_nIndex].m_Doing != do_stand &&
- Npc[m_nIndex].m_Doing != do_sit)
- return;
-
- if (Npc[m_nIndex].m_Dir < MAX_NPC_DIR / 2)
- Npc[m_nIndex].m_Dir += MAX_NPC_DIR / 2;
- else
- Npc[m_nIndex].m_Dir -= MAX_NPC_DIR / 2;
- }
- void KPlayer::FindSelectNpc(int x, int y, int nRelation)
- {
- int nNpcIdx = 0;
-
- nNpcIdx = NpcSet.SearchNpcAt(x, y, nRelation, 40);
-
- if (nNpcIdx)
- m_nPeapleIdx = nNpcIdx;
- else
- m_nPeapleIdx = 0;
- }
- void KPlayer::FindSelectObject(int x, int y)
- {
- int nObjIdx = 0;
-
- nObjIdx = ObjSet.SearchObjAt(x, y, 40);
- if (nObjIdx)
- m_nObjectIdx = nObjIdx;
- else
- m_nObjectIdx = 0;
- }
- // need change
- int KPlayer::NetCommandPlayerTalk(BYTE * pProtocol)
- {
- /* DWORD dwNpcID;
- int nSize;
- dwNpcID = *(DWORD *) &pProtocol[1];
- nSize = pProtocol[5];
- int nIdx = NpcSet.SearchID(dwNpcID);
- if (ConformIdx(nIdx))
- {
- strcpy(Npc[nIdx].m_szChatBuffer, (char *)(pProtocol+6));
- Npc[nIdx].m_nCurChatTime = NPC_SHOW_CHAT_TIME_LENGTH;
- }
-
- return (7 + nSize); // need test
- */
- return 0;
- }
- BOOL KPlayer::ConformIdx(int nIdx)
- {
- if (nIdx == m_nIndex || nIdx == 0)
- return FALSE;
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- BOOL KPlayer::IsWaitingRemove()
- {
- if (!m_dwID)
- return FALSE;
- return m_bIsQuiting;
- }
- void KPlayer::WaitForRemove()
- {
- m_bIsQuiting = TRUE;
- }
- BOOL KPlayer::IsLoginTimeOut()
- {
- if (m_nNetConnectIdx != -1)
- return FALSE;
-
- if (!m_dwID)
- return FALSE;
-
- if (-1 != m_dwLoginTime &&
- g_SubWorldSet.GetGameTime() - m_dwLoginTime > defPLAYER_LOGIN_TIMEOUT)
- {
- // m_dwLoginTime = -1;
- return TRUE;
- }
-
- return FALSE;
- }
- void KPlayer::LoginTimeOut()
- {
- // 通知聊天好友自己下线了
- m_cChat.OffLine(m_dwID);
-
- m_pStatusLoadPlayerInfo = NULL;
-
- Release();
- }
- BOOL KPlayer::Save()
- {
- if (m_nIndex <= 0 && m_dwID == 0)
- return FALSE;
-
- /* if (m_uMustSave != SAVE_IDLE)
- return FALSE;
- */
- TRoleData* pData = (TRoleData *)m_SaveBuffer;
-
- if (UpdateDBPlayerInfo((BYTE *)pData) == -1)
- return FALSE;
- /*
- #ifdef _DEBUG
- KFile File;
- char szFileName[32];
- sprintf(szFileName, "d:\%sSave.Buf", m_PlayerName);
- File.Create(szFileName);
- File.Write(pData, pData->dwDataLen);
- File.Close();
- #endif
- */
- _ASSERT(pData->dwDataLen < sizeof(m_SaveBuffer));
- if (pData->dwDataLen <= 0)
- return FALSE;
-
- // m_uMustSave = SAVE_REQUEST;
- m_ulLastSaveTime = g_SubWorldSet.GetGameTime();
- return TRUE;
- }
- BOOL KPlayer::CanSave()
- {
- if (m_nNetConnectIdx == -1)
- return FALSE;
-
- if (m_nIndex <= 0)
- return FALSE;
-
- if (m_bExchangeServer)
- return FALSE;
-
- if (m_bIsQuiting)
- return FALSE;
-
- if (CheckTrading())
- {
- return FALSE;
- }
-
- if (m_uMustSave == SAVE_DOING && g_SubWorldSet.GetGameTime() - m_ulLastSaveTime > defPLAYER_SAVE_TIMEOUT)
- return TRUE;
-
- if (m_uMustSave != SAVE_IDLE)
- return FALSE;
-
- return TRUE;
- }
- BOOL KPlayer::SendSyncData(int &nStep, unsigned int &nParam)
- {
- BOOL bRet = FALSE;
- switch(nStep)
- {
- case STEP_BASE_INFO:
- {
- bRet = SubWorld[Npc[m_nIndex].m_SubWorldIndex].SendSyncData(m_nIndex, m_nNetConnectIdx);
- if (!bRet)
- {
- printf("SubWorld Fail.n");
- break;
- }
- bRet = Npc[m_nIndex].SendSyncData(m_nNetConnectIdx);
- if (!bRet)
- {
- printf("NPC Fail.n");
- break;
- }
- // 这个消息必须在同步世界NPC数据后做,使客户端能找到当前玩家在客户端的Npc索引
- CURPLAYER_SYNC sSync; // 同步当前玩家的自身独特信息给客户端(装备等)
- sSync.ProtocolType = (BYTE)s2c_synccurplayer;
- sSync.m_dwID = Npc[m_nIndex].m_dwID;
- sSync.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
- sSync.m_btSex = Npc[m_nIndex].m_nSex;
- sSync.m_btKind = Npc[m_nIndex].m_Kind;
- sSync.m_btSeries = Npc[m_nIndex].m_Series;
- sSync.m_wLifeMax = Npc[m_nIndex].m_LifeMax;
- sSync.m_wStaminaMax = Npc[m_nIndex].m_StaminaMax;
- sSync.m_wManaMax = Npc[m_nIndex].m_ManaMax;
- sSync.m_HeadImage = Npc[m_nIndex].m_HeadImage;
- sSync.m_wAttributePoint = this->m_nAttributePoint;
- sSync.m_wSkillPoint = this->m_nSkillPoint;
- sSync.m_wStrength = this->m_nStrength;
- sSync.m_wDexterity = this->m_nDexterity;
- sSync.m_wVitality = this->m_nVitality;
- sSync.m_wEngergy = this->m_nEngergy;
- sSync.m_wLucky = this->m_nLucky;
- sSync.m_nExp = this->m_nExp;
- sSync.m_dwLeadExp = this->m_dwLeadExp;
- sSync.m_btCurFaction = this->m_cFaction.m_nCurFaction;
- sSync.m_btFirstFaction = this->m_cFaction.m_nFirstAddFaction;
- sSync.m_nFactionAddTimes = this->m_cFaction.m_nAddTimes;
- sSync.m_wWorldStat = (WORD)m_nWorldStat;
- sSync.m_wSectStat = (WORD)m_nSectStat;
- sSync.m_nMoney1 = this->m_ItemList.GetMoney(room_equipment);
- sSync.m_nMoney2 = this->m_ItemList.GetMoney(room_repository);
- if (SUCCEEDED(g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(CURPLAYER_SYNC))))
- {
- bRet = TRUE;
- }
- else
- {
- printf("player Packing sync data failed...n");
- bRet = FALSE;
- break;
- }
- }
- break;
- case STEP_FIGHT_SKILL_LIST:
- {
- bRet = SendSyncData_Skill();
- }
- break;
- case STEP_LIFE_SKILL_LIST:
- bRet = TRUE;
- break;
- case STEP_ITEM_LIST:
- bRet = TRUE;
- break;
- case STEP_TASK_LIST:
- bRet = TRUE;
- break;
- case STEP_SYNC_END:
- bRet = TRUE;
- break;
- }
- if (!bRet)
- {
- printf("Load PlayerInfo Step %d Failed...n", nStep);
- }
- return bRet;
- }
- BOOL KPlayer::SendSyncData_Skill()
- {
- SKILL_SEND_ALL_SYNC sSkill;
-
- sSkill.ProtocolType = s2c_synccurplayerskill;
- sSkill.m_wProtocolLong = 2;
- int i;
- int j;
- for (i = 0,j = 0; i < MAX_NPCSKILL; i++)
- {
- sSkill.m_sAllSkill[i].SkillId = 0;
- sSkill.m_sAllSkill[i].SkillLevel = 0;
- if( Npc[m_nIndex].m_SkillList.m_Skills[i].SkillId <= 0)
- continue;
- sSkill.m_sAllSkill[j].SkillId = Npc[m_nIndex].m_SkillList.m_Skills[i].SkillId;
- sSkill.m_sAllSkill[j].SkillLevel = Npc[m_nIndex].m_SkillList.m_Skills[i].SkillLevel;
- j++;
- }
- sSkill.m_wProtocolLong += sizeof(SKILL_SEND_ALL_SYNC_DATA) * j;
-
- if (SUCCEEDED(g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSkill, sSkill.m_wProtocolLong + 1)))
- {
- return TRUE;
- }
- else
- {
- printf("player Packing skill sync data failed...n");
- return FALSE;
- }
- }
- void KPlayer::SendCurNormalSyncData()
- {
- CURPLAYER_NORMAL_SYNC sSync;
-
- sSync.ProtocolType = s2c_synccurplayernormal;
- sSync.m_shLife = Npc[m_nIndex].m_CurrentLife;
- sSync.m_shStamina = Npc[m_nIndex].m_CurrentStamina;
- sSync.m_shMana = Npc[m_nIndex].m_CurrentMana;
- sSync.m_shAngry = 0;
- if ( !m_cTeam.m_nFlag )
- sSync.m_btTeamData = 0;
- else
- {
- if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
- sSync.m_btTeamData = 0x03;
- else
- sSync.m_btTeamData = 0x01;
- }
-
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(CURPLAYER_NORMAL_SYNC));
- }
- void KPlayer::QuitGame(int nType)
- {
- Save();
- }
- void KPlayer::BuyItem(BYTE* pProtocol)
- {
- PLAYER_BUY_ITEM_COMMAND* pCommand = (PLAYER_BUY_ITEM_COMMAND *)pProtocol;
- BuySell.Buy(m_nPlayerIndex, m_BuyInfo.m_nBuyIdx, pCommand->m_BuyIdx, pCommand->m_Place, pCommand->m_X, pCommand->m_Y);
- }
- void KPlayer::SellItem(BYTE* pProtocol)
- {
- PLAYER_SELL_ITEM_COMMAND* pCommand = (PLAYER_SELL_ITEM_COMMAND *)pProtocol;
- BuySell.Sell(m_nPlayerIndex, m_BuyInfo.m_nBuyIdx, m_ItemList.SearchID(pCommand->m_ID));
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:获取玩家重生点位置
- //-------------------------------------------------------------------------
- void KPlayer::GetLoginRevivalPos(int *lpnSubWorld, int *lpnMpsX, int *lpnMpsY)
- {
- *lpnSubWorld = m_sLoginRevivalPos.m_nSubWorldID;
- *lpnMpsX = m_sLoginRevivalPos.m_nMpsX;
- *lpnMpsY = m_sLoginRevivalPos.m_nMpsY;
- }
- void KPlayer::GetDeathRevivalPos(int *lpnSubWorld, int *lpnMpsX, int *lpnMpsY)
- {
- *lpnSubWorld = m_sDeathRevivalPos.m_nSubWorldID;
- *lpnMpsX = m_sDeathRevivalPos.m_nMpsX;
- *lpnMpsY = m_sDeathRevivalPos.m_nMpsY;
- }
- #endif
- #ifdef _SERVER
- void KPlayer::SetTimer(DWORD nTime, int nTimerTaskId) //时间任务脚本,开启计时器
- {
- if (!nTime || !nTimerTaskId) return ;
- m_TimerTask.SetTimer(nTime, nTimerTaskId);
- }
- void KPlayer::CloseTimer() //关闭时间计时器
- {
- m_TimerTask.CloseTimer();
- }
- #endif
- #ifdef _SERVER
- //------------------------------------------------------------------------------
- // 功能:设定玩家重生点位置
- //------------------------------------------------------------------------------
- void KPlayer::SetRevivalPos(int nSubWorld, int nReviveId)
- {
- if (nSubWorld >= 0) //如果小于0,表示沿用当前的
- {
- m_sLoginRevivalPos.m_nSubWorldID = nSubWorld;
- }
- else
- {
- m_sLoginRevivalPos.m_nSubWorldID = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_SubWorldID;
- }
-
- POINT Pos;
-
- g_SubWorldSet.GetRevivalPosFromId(m_sLoginRevivalPos.m_nSubWorldID, nReviveId, &Pos);
- m_sLoginRevivalPos.m_ReviveID = nReviveId;
- m_sLoginRevivalPos.m_nMpsX = Pos.x;
- m_sLoginRevivalPos.m_nMpsY = Pos.y;
-
- m_sDeathRevivalPos = m_sLoginRevivalPos;
- }
- #endif
- #ifdef _SERVER
- //------------------------------------------------------------------------------
- // 功能:收到客户端查询某个npc组队信息的申请后,向这个客户端发送队伍信息
- //------------------------------------------------------------------------------
- void KPlayer::S2CSendTeamInfo(BYTE* pProtocol)
- {
- PLAYER_APPLY_TEAM_INFO *pApplyTeamInfo = (PLAYER_APPLY_TEAM_INFO*)pProtocol;
-
- //------------------------------ 查询自身组队信息 -----------------------------
- if (pApplyTeamInfo->m_dwTarNpcID == Npc[m_nIndex].m_dwID)
- {
- SendSelfTeamInfo();
- return;
- }
-
- //--------------------------- 查询其他 npc 组队信息 -----------------------------
- PLAYER_SEND_TEAM_INFO sTeamInfo;
- PLAYER_APPLY_TEAM_INFO_FALSE sTeamInfoFalse;
- // 寻找相应 npc id 的 player 编号
- int nPlayer, nRegionNo, i;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(pApplyTeamInfo->m_dwTarNpcID);
- if ( nPlayer >= 0)
- goto SendMsg;
- for (i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(pApplyTeamInfo->m_dwTarNpcID);
- if (nPlayer >= 0)
- break;
- }
- if (i >= 8)
- goto SendFalse;
-
- SendMsg:
- // 寻找队伍
- KTeam *pTeam;
- if ( !Player[nPlayer].m_cTeam.m_nFlag )
- goto SendFalse;
- pTeam = &g_Team[Player[nPlayer].m_cTeam.m_nID];
- if (pTeam->m_nCaptain < 0 || !pTeam->IsOpen())
- goto SendFalse;
-
- // 发送队伍消息
- sTeamInfo.ProtocolType = (BYTE)s2c_teaminfo;
- sTeamInfo.m_nCaptain = Npc[Player[pTeam->m_nCaptain].m_nIndex].m_dwID;
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (pTeam->m_nMember[i] < 0)
- sTeamInfo.m_nMember[i] = 0;
- else
- sTeamInfo.m_nMember[i] = Npc[Player[pTeam->m_nMember[i]].m_nIndex].m_dwID;
- }
- // strcpy(sTeamInfo.m_szTeamName, pTeam->m_szName);
-
- // 发送
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sTeamInfo, sizeof(PLAYER_SEND_TEAM_INFO));
- return;
-
- // 发送失败通知
- SendFalse:
- sTeamInfoFalse.ProtocolType = s2c_teamapplyinfofalse;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sTeamInfoFalse, sizeof(PLAYER_APPLY_TEAM_INFO_FALSE));
- return;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:服务器向客户端发送队伍信息
- //-------------------------------------------------------------------------
- void KPlayer::SendSelfTeamInfo()
- {
- if (m_cTeam.m_nFlag && m_cTeam.m_nID >= 0) // 发送队伍信息
- {
- int nNpcIndex;
- PLAYER_SEND_SELF_TEAM_INFO sSelfInfo;
- sSelfInfo.ProtocolType = s2c_teamselfinfo;
- sSelfInfo.nTeamServerID = m_cTeam.m_nID;
- sSelfInfo.m_dwLeadExp = m_dwLeadExp;
- sSelfInfo.m_btState = g_Team[m_cTeam.m_nID].m_nState;
-
- // 队长
- nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex;
- sSelfInfo.m_dwNpcID[0] = Npc[nNpcIndex].m_dwID;
- sSelfInfo.m_btLevel[0] = (DWORD)Npc[nNpcIndex].m_Level;
- strcpy(sSelfInfo.m_szNpcName[0], Npc[nNpcIndex].Name);
- // 队员
- for (int i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0)
- {
- nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
- sSelfInfo.m_dwNpcID[i + 1] = Npc[nNpcIndex].m_dwID;
- sSelfInfo.m_btLevel[i + 1] = (DWORD)Npc[nNpcIndex].m_Level;
- strcpy(sSelfInfo.m_szNpcName[i + 1], Npc[nNpcIndex].Name);
- }
- else
- {
- sSelfInfo.m_dwNpcID[i + 1] = 0;
- sSelfInfo.m_btLevel[i + 1] = 0;
- }
- }
- // 发送消息
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSelfInfo, sizeof(PLAYER_SEND_SELF_TEAM_INFO));
- }
- else // 发送离队信息
- {
- PLAYER_LEAVE_TEAM sLeaveTeam;
- sLeaveTeam.ProtocolType = s2c_teamleave;
- sLeaveTeam.m_dwNpcID = Npc[m_nIndex].m_dwID;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求创建一支队伍
- //-------------------------------------------------------------------------
- BOOL KPlayer::CreateTeam(BYTE* pProtocol)
- {
- return m_cTeam.CreateTeam(this->m_nPlayerIndex, (PLAYER_APPLY_CREATE_TEAM*)pProtocol);
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求开放、关闭本player队伍是否允许队员加入状态
- //-------------------------------------------------------------------------
- BOOL KPlayer::SetTeamState(BYTE* pProtocol)
- {
- if (this->CheckTrading())
- return FALSE;
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN || m_cTeam.m_nID < 0)
- {
- SendSelfTeamInfo();
- return FALSE;
- }
-
- PLAYER_TEAM_OPEN_CLOSE *pTeamState = (PLAYER_TEAM_OPEN_CLOSE*)pProtocol;
- if (pTeamState->m_btOpenClose == 0)
- {
- g_Team[m_cTeam.m_nID].SetTeamClose();
- }
- else
- {
- if (m_cMenuState.m_nState == PLAYER_MENU_STATE_TRADEOPEN)
- m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
- g_Team[m_cTeam.m_nID].SetTeamOpen();
- }
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求加入一支队伍
- //-------------------------------------------------------------------------
- BOOL KPlayer::S2CSendAddTeamInfo(BYTE* pProtocol)
- {
- if (!m_cTeam.m_bCanTeamFlag)
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_CANNOT_ADD_TEAM;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
-
- PLAYER_APPLY_ADD_TEAM *pAddTeam = (PLAYER_APPLY_ADD_TEAM*)pProtocol;
-
- // 寻找队长 npc id 的 player 编号
- int nPlayer, nRegionNo, i;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(pAddTeam->m_dwTarNpcID);
- if ( nPlayer >= 0)
- goto SendMsg;
- for (i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(pAddTeam->m_dwTarNpcID);
- if (nPlayer >= 0)
- break;
- }
- if (i >= 8)
- return FALSE;
-
- SendMsg:
- if (Npc[Player[nPlayer].m_nIndex].m_Camp == camp_begin && Npc[m_nIndex].m_Camp != camp_begin)
- return FALSE;
- m_cTeam.m_nApplyCaptainID = pAddTeam->m_dwTarNpcID;
- PLAYER_APPLY_ADD_TEAM sAddTeam;
- sAddTeam.ProtocolType = s2c_teamgetapply;
- sAddTeam.m_dwTarNpcID = Npc[m_nIndex].m_dwID;
- g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sAddTeam, sizeof(PLAYER_APPLY_ADD_TEAM));
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长通知服务器接受某个npc为队伍成员
- //-------------------------------------------------------------------------
- BOOL KPlayer::AddTeamMember(BYTE* pProtocol)
- {
- // 错误检测(是否组队、是否队长、队伍开放状态、队员数、统率力)
- if ( !m_cTeam.m_nFlag ||
- m_cTeam.m_nFigure != TEAM_CAPTAIN ||
- !g_Team[m_cTeam.m_nID].IsOpen() ||
- g_Team[m_cTeam.m_nID].m_nMemNum >= MAX_TEAM_MEMBER ||
- g_Team[m_cTeam.m_nID].m_nMemNum >= g_Team[m_cTeam.m_nID].CalcCaptainPower())
- {
- SendSelfTeamInfo();
- return FALSE;
- }
-
- // 从npc id查找player
- int nPlayer, i;
- PLAYER_ACCEPT_TEAM_MEMBER *pAccept = (PLAYER_ACCEPT_TEAM_MEMBER*)pProtocol;
- nPlayer = FindAroundPlayer(pAccept->m_dwNpcID);
- if (nPlayer < 0)
- return FALSE;
- // 对方正处于不能组队状态
- if (!Player[nPlayer].m_cTeam.m_bCanTeamFlag)
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TARGET_CANNOT_ADD_TEAM;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- return FALSE;
- }
- // 已经在队伍中
- if (Player[nPlayer].m_cTeam.m_nFlag)
- return FALSE;
- if (Player[nPlayer].m_cTeam.m_nApplyCaptainID != Npc[this->m_nIndex].m_dwID)
- return FALSE;
- // 队伍添加成员
- if ( !g_Team[m_cTeam.m_nID].AddMember(nPlayer) )
- return FALSE;
- // 改变队伍状态
- if (g_Team[m_cTeam.m_nID].m_nMemNum >= MAX_TEAM_MEMBER || g_Team[m_cTeam.m_nID].CheckFull())
- {
- g_Team[m_cTeam.m_nID].SetTeamClose();
- }
- // 被接受队员队伍数据处理
- Player[nPlayer].m_cTeam.Release();
- Player[nPlayer].m_cTeam.m_nFlag = 1;
- Player[nPlayer].m_cTeam.m_nFigure = TEAM_MEMBER;
- Player[nPlayer].m_cTeam.m_nID = m_cTeam.m_nID;
- Npc[Player[nPlayer].m_nIndex].SetCurrentCamp(Npc[m_nIndex].m_Camp);
-
- // 给各个队员发消息
- PLAYER_TEAM_ADD_MEMBER sAddMem;
- sAddMem.ProtocolType = s2c_teamaddmember;
- sAddMem.m_dwNpcID = Npc[Player[nPlayer].m_nIndex].m_dwID;
- sAddMem.m_btLevel = (DWORD)Npc[Player[nPlayer].m_nIndex].m_Level;
- strcpy(sAddMem.m_szName, Npc[Player[nPlayer].m_nIndex].Name);
-
- // 给队长发消息
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sAddMem, sizeof(PLAYER_TEAM_ADD_MEMBER));
-
- // 给老队员发消息
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] < 0 || g_Team[m_cTeam.m_nID].m_nMember[i] == nPlayer)
- continue;
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sAddMem, sizeof(PLAYER_TEAM_ADD_MEMBER));
- }
-
- // ------------------------------------- 给新队员发消息 --------------------------
- int nNpcIndex;
- PLAYER_SEND_SELF_TEAM_INFO sSelfInfo;
- sSelfInfo.ProtocolType = s2c_teamselfinfo;
- sSelfInfo.nTeamServerID = m_cTeam.m_nID;
- sSelfInfo.m_dwLeadExp = Player[nPlayer].m_dwLeadExp;
- sSelfInfo.m_btState = g_Team[m_cTeam.m_nID].m_nState;
- // 队长数据
- nNpcIndex = m_nIndex;
- sSelfInfo.m_dwNpcID[0] = Npc[nNpcIndex].m_dwID;
- sSelfInfo.m_btLevel[0] = (DWORD)Npc[nNpcIndex].m_Level;
- strcpy(sSelfInfo.m_szNpcName[0], Npc[nNpcIndex].Name);
- // 队员数据
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0)
- {
- nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
- sSelfInfo.m_dwNpcID[i + 1] = Npc[nNpcIndex].m_dwID;
- sSelfInfo.m_btLevel[i + 1] = (DWORD)Npc[nNpcIndex].m_Level;
- strcpy(sSelfInfo.m_szNpcName[i + 1], Npc[nNpcIndex].Name);
- }
- else
- {
- sSelfInfo.m_dwNpcID[i + 1] = 0;
- sSelfInfo.m_btLevel[i + 1] = 0;
- }
- }
- // 发送消息
- g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sSelfInfo, sizeof(PLAYER_SEND_SELF_TEAM_INFO));
-
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_SELF_ADD;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- sMsg.m_lpBuf = 0;
- g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
-
- // --------------------------------- 给新队员发消息 end --------------------------
-
- return TRUE;
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端队员通知离开队伍
- //-------------------------------------------------------------------------
- void KPlayer::LeaveTeam(BYTE* pProtocol)
- {
- if (!m_cTeam.m_nFlag)
- return;
- if (this->m_cTeam.m_nFigure == TEAM_CAPTAIN && g_Team[m_cTeam.m_nID].IsOpen())
- {
- g_Team[m_cTeam.m_nID].SetTeamClose();
- }
-
- // 非队长离开队伍,发系统消息,队长离开队伍的系统消息处理在DeleteMember里面
- if (m_cTeam.m_nFigure != TEAM_CAPTAIN)
- {
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_LEAVE;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- sMsg.m_lpBuf = (void*)Npc[this->m_nIndex].m_dwID;
-
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- for (int i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] > 0)
- {
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- }
- }
- sMsg.m_lpBuf = 0;
- }
-
- // 服务器端队员离开的处理
- g_Team[m_cTeam.m_nID].DeleteMember(GetPlayerIndex());
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端队长通知踢出某个队员
- //-------------------------------------------------------------------------
- void KPlayer::TeamKickOne(BYTE* pProtocol)
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
-
- int nMemNo;
- PLAYER_TEAM_KICK_MEMBER *pKickOne = (PLAYER_TEAM_KICK_MEMBER*)pProtocol;
- nMemNo = g_Team[m_cTeam.m_nID].FindMemberID(pKickOne->m_dwNpcID);
- if (nMemNo < 0)
- return;
- int nPlayerNo;
- // 服务器端队员离开的处理
- nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[nMemNo];
- g_Team[m_cTeam.m_nID].DeleteMember(nPlayerNo);
-
- // 发消息给客户端
- int nLength;
- SHOW_MSG_SYNC sMsg;
-
- nLength = strlen(Npc[Player[nPlayerNo].m_nIndex].Name);
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_KICK_One;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID) + nLength;
- sMsg.m_lpBuf = new BYTE[sMsg.m_wLength + 1];
-
- memcpy(sMsg.m_lpBuf, &sMsg, sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID));
- memcpy((char*)sMsg.m_lpBuf + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), Npc[Player[nPlayerNo].m_nIndex].Name, nLength);
-
- g_pServer->PackDataToClient(Player[nPlayerNo].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
-
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
- for (int i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] > 0)
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
- }
- sMsg.Release();
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端队长通知把队长身份交给某个队员
- //-------------------------------------------------------------------------
- void KPlayer::TeamChangeCaptain(BYTE* pProtocol)
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
- int i, nMember, nPlayerNo, nIsOpen = 0;
- PLAYER_APPLY_TEAM_CHANGE_CAPTAIN *pChange = (PLAYER_APPLY_TEAM_CHANGE_CAPTAIN*)pProtocol;
- nMember = g_Team[m_cTeam.m_nID].FindMemberID(pChange->m_dwNpcID);
- if (nMember < 0)
- return;
- if (Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[nMember]].m_nIndex].m_Camp == camp_begin && Npc[this->m_nIndex].m_Camp != camp_begin)
- {
- // 队长移交失败:对方统帅力不够
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL2;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- sMsg.m_lpBuf = (LPVOID)pChange->m_dwNpcID;
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
- return;
- }
- if (g_Team[m_cTeam.m_nID].m_nMemNum > PlayerSet.m_cLeadExp.GetMemNumFromLevel(Player[g_Team[m_cTeam.m_nID].m_nMember[nMember]].m_dwLeadLevel))
- {
- // 队长移交失败:对方统帅力不够
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- sMsg.m_lpBuf = (LPVOID)pChange->m_dwNpcID;
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
- return;
- }
- if (g_Team[m_cTeam.m_nID].IsOpen())
- {
- g_Team[m_cTeam.m_nID].SetTeamClose();
- nIsOpen = 1;
- }
- nPlayerNo = g_Team[m_cTeam.m_nID].m_nCaptain;
- g_Team[m_cTeam.m_nID].m_nCaptain = g_Team[m_cTeam.m_nID].m_nMember[nMember];
- g_Team[m_cTeam.m_nID].m_nMember[nMember] = nPlayerNo;
- m_cTeam.m_nFigure = TEAM_MEMBER;
- Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_cTeam.m_nFigure = TEAM_CAPTAIN;
- // 改变阵营
- Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].RestoreCurrentCamp();
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[i];
- if (nPlayerNo < 0)
- continue;
- Npc[Player[nPlayerNo].m_nIndex].SetCurrentCamp(Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].m_Camp);
- }
-
- // 给各个队员发消息
- PLAYER_TEAM_CHANGE_CAPTAIN sChangeCaptain;
- sChangeCaptain.ProtocolType = s2c_teamchangecaptain;
- sChangeCaptain.m_dwCaptainID = pChange->m_dwNpcID;
- sChangeCaptain.m_dwMemberID = Npc[m_nIndex].m_dwID;
- // 给队长发消息
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, (BYTE*)&sChangeCaptain, sizeof(PLAYER_TEAM_CHANGE_CAPTAIN));
- // 给队员发消息
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[i];
- if (nPlayerNo < 0)
- continue;
- g_pServer->PackDataToClient(Player[nPlayerNo].m_nNetConnectIdx, (BYTE*)&sChangeCaptain, sizeof(PLAYER_TEAM_CHANGE_CAPTAIN));
- }
-
- if (nIsOpen)
- {
- g_Team[m_cTeam.m_nID].SetTeamOpen();
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端队长请求解散队伍
- //-------------------------------------------------------------------------
- void KPlayer::TeamDismiss(BYTE* pProtocol)
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
-
- PLAYER_LEAVE_TEAM sLeaveTeam;
- int i;
- SHOW_MSG_SYNC sMsg;
-
- // 队伍解散消息
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_TEAM_DISMISS;
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
- g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
-
- // 给队长发消息
- sLeaveTeam.ProtocolType = s2c_teamleave;
- sLeaveTeam.m_dwNpcID = Npc[m_nIndex].m_dwID;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
- // 给队员发消息
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
-
- sLeaveTeam.m_dwNpcID = Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].m_dwID;
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
- // 队员身份改变
- Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_cTeam.m_nFlag = 0;
- Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].RestoreCurrentCamp();;
- }
- // 队伍清空
- g_Team[m_cTeam.m_nID].Release();
- // 队长身份改变
- m_cTeam.m_nFlag = 0;
- Npc[m_nIndex].RestoreCurrentCamp();
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求设定PK状态
- //-------------------------------------------------------------------------
- void KPlayer::SetPK(BYTE* pProtocol)
- {
- PLAYER_SET_PK *pPK = (PLAYER_SET_PK*)pProtocol;
-
- if (pPK->m_btPKFlag)
- Npc[m_nIndex].SetCurrentCamp(camp_free);
- else
- Npc[m_nIndex].RestoreCurrentCamp();
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:收到客户端请求获得门派数据
- //-------------------------------------------------------------------------
- void KPlayer::SendFactionData(BYTE* pProtocol)
- {
- SendFactionData();
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:向客户端发送门派数据
- //-------------------------------------------------------------------------
- void KPlayer::SendFactionData()
- {
- // 给客户端发消息
- PLAYER_FACTION_DATA sData;
- sData.ProtocolType = s2c_playerfactiondata;
- sData.m_btCamp = Npc[m_nIndex].m_Camp;
- sData.m_btCurFaction = m_cFaction.m_nCurFaction;
- sData.m_btFirstFaction = m_cFaction.m_nFirstAddFaction;
- sData.m_nAddTimes = m_cFaction.m_nAddTimes;
-
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sData, sizeof(PLAYER_FACTION_DATA));
- }
- #endif
- #ifdef _SERVER
- // not end
- void KPlayer::GetAboutPos(KMapPos *pMapPos)
- {
- if (m_nIndex <= 0)
- return;
-
- if (Npc[m_nIndex].m_SubWorldIndex < 0)
- return;
-
- POINT Pos;
- int nX, nY;
- Npc[m_nIndex].GetMpsPos(&nX, &nY);
- Pos.x = nX;
- Pos.y = nY;
-
- SubWorld[Npc[m_nIndex].m_SubWorldIndex].GetFreeObjPos(Pos);
-
- pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
- SubWorld[Npc[m_nIndex].m_SubWorldIndex].Mps2Map(
- Pos.x,
- Pos.y,
- &pMapPos->nRegion,
- &pMapPos->nMapX,
- &pMapPos->nMapY,
- &pMapPos->nOffX,
- &pMapPos->nOffY);
- }
- /*
- void KPlayer::GetAboutPos(KMapPos *pMapPos)
- {
- POINT Pos[8] =
- {
- {0, 32}, {-32, 32}, {-32, 0}, {-32, -32},
- {0, -32}, {32, -32}, {32, 0}, {32, 32},
- };
- int nMpsX, nMpsY, nTmpX, nTmpY;
- int nR, nMapX, nMapY, nOffX, nOffY;
- Npc[m_nIndex].GetMpsPos(&nMpsX, &nMpsY);
-
- for (int i = 0; i < 8; i++)
- {
- nTmpX = nMpsX + Pos[i].x;
- nTmpY = nMpsY + Pos[i].y;
- if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].GetBarrier(nTmpX, nTmpY))
- continue;
- SubWorld[Npc[m_nIndex].m_SubWorldIndex].Mps2Map(nTmpX, nTmpY, &nR, &nMapX, &nMapY, &nOffX, &nOffY);
- if (nR == -1)
- continue;
- if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nR].GetRef(nMapX, nMapY, obj_object))
- continue;
- else
- break;
- }
-
- if (i == 8)
- {
- pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
- pMapPos->nRegion = Npc[m_nIndex].m_RegionIndex;
- pMapPos->nMapX = Npc[m_nIndex].m_MapX;
- pMapPos->nMapY = Npc[m_nIndex].m_MapY;
- pMapPos->nOffX = Npc[m_nIndex].m_OffX;
- pMapPos->nOffY = Npc[m_nIndex].m_OffY;
- }
- else
- {
- pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
- pMapPos->nRegion = nR;
- pMapPos->nMapX = nMapX;
- pMapPos->nMapY = nMapY;
- pMapPos->nOffX = nOffX;
- pMapPos->nOffY = nOffY;
- }
- }*/
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:寻找玩家周围的某个指定npc id的player index
- //-------------------------------------------------------------------------
- int KPlayer::FindAroundPlayer(DWORD dwNpcID)
- {
- if (dwNpcID == 0)
- return -1;
-
- int nPlayer, nRegionNo, i;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(dwNpcID);
- if ( nPlayer >= 0)
- return nPlayer;
- for (i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(dwNpcID);
- if (nPlayer >= 0)
- return nPlayer;
- }
-
- return -1;
- }
- //-------------------------------------------------------------------------
- // 功能:判断某玩家是否在周围
- //-------------------------------------------------------------------------
- BOOL KPlayer::CheckPlayerAround(int nPlayerIdx)
- {
- if (nPlayerIdx <= 0)
- return FALSE;
- if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].CheckPlayerIn(nPlayerIdx))
- return TRUE;
- int nRegionNo;
- for (int i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].CheckPlayerIn(nPlayerIdx))
- return TRUE;
- }
-
- return FALSE;
- }
- //-------------------------------------------------------------------------
- // 功能:寻找玩家周围的某个指定npc id的npc index
- //-------------------------------------------------------------------------
- int KPlayer::FindAroundNpc(DWORD dwNpcID)
- {
- if (dwNpcID == 0)
- return 0;
-
- int nNpc, nRegionNo, i;
- nNpc = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].SearchNpc(dwNpcID);
- if ( nNpc > 0)
- return nNpc;
- for (i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- nNpc = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].SearchNpc(dwNpcID);
- if (nNpc > 0)
- return nNpc;
- }
-
- return 0;
- }
- #endif
- //-------------------------------------------------------------------------
- // 功能:新玩家登陆时根据五行属性产生 力量 敏捷 活力 精力 四项数值
- //-------------------------------------------------------------------------
- BOOL KPlayer::NewPlayerGetBaseAttribute(int Series)
- {
- if (Series < series_metal || Series > series_earth)
- return FALSE;
-
- Npc[m_nIndex].SetSeries(Series);
-
- m_nStrength = PlayerSet.m_cNewPlayerAttribute.m_nStrength[Series];
- m_nDexterity = PlayerSet.m_cNewPlayerAttribute.m_nDexterity[Series];
- m_nVitality = PlayerSet.m_cNewPlayerAttribute.m_nVitality[Series];
- m_nEngergy = PlayerSet.m_cNewPlayerAttribute.m_nEngergy[Series];
- m_nLucky = PlayerSet.m_cNewPlayerAttribute.m_nLucky[Series];
-
- m_nCurStrength = m_nStrength;
- m_nCurDexterity = m_nDexterity;
- m_nCurVitality = m_nVitality;
- m_nCurEngergy = m_nEngergy;
- CalcCurLucky();
-
- m_cFaction.SetSeries(Series);
-
- return TRUE;
- }
- //-------------------------------------------------------------------------
- // 功能:计算当前力量
- //-------------------------------------------------------------------------
- //void KPlayer::CalcCurStrength()
- //{ // 还需要考虑 装备、技能、状态 的影响
- // m_nCurStrength = m_nStrength;
- //}
- //-------------------------------------------------------------------------
- // 功能:计算当前敏捷
- //-------------------------------------------------------------------------
- //void KPlayer::CalcCurDexterity()
- //{ // 还需要考虑 装备、技能、状态 的影响
- // m_nCurDexterity = m_nDexterity;
- //}
- //-------------------------------------------------------------------------
- // 功能:计算当前活力
- //-------------------------------------------------------------------------
- //void KPlayer::CalcCurVitality()
- //{ // 还需要考虑 装备、技能、状态 的影响
- // m_nCurVitality = m_nVitality;
- //}
- //-------------------------------------------------------------------------
- // 功能:计算当前精力
- //-------------------------------------------------------------------------
- //void KPlayer::CalcCurEngergy()
- //{ // 还需要考虑 装备、技能、状态 的影响
- // m_nCurEngergy = m_nEngergy;
- //}
- //-------------------------------------------------------------------------
- // 功能:计算当前运气
- //-------------------------------------------------------------------------
- void KPlayer::CalcCurLucky()
- { // 还需要考虑 装备、技能、状态 的影响
- m_nCurLucky = m_nLucky;
- }
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:增加基本力量
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseStrength(int nData)
- {
- if (nData > 0 && nData <= m_nAttributePoint)
- {
- m_nStrength += nData;
- m_nAttributePoint -= nData;
- m_nCurStrength += nData;
-
- UpdataCurData();
- SetNpcPhysicsDamage();
- // 把当前力量传给客户端
- PLAYER_ATTRIBUTE_SYNC sSync;
- sSync.ProtocolType = s2c_playersyncattribute;
- sSync.m_btAttribute = 0;
- sSync.m_nBasePoint = m_nStrength;
- sSync.m_nCurPoint = m_nCurStrength;
- sSync.m_nLeavePoint = m_nAttributePoint;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:增加基本敏捷
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseDexterity(int nData)
- {
- if (nData > 0 && nData <= m_nAttributePoint)
- {
- m_nDexterity += nData;
- m_nAttributePoint -= nData;
- m_nCurDexterity += nData;
-
- SetNpcAttackRating();
- SetNpcDefence();
- UpdataCurData();
- SetNpcPhysicsDamage();
-
- // 把当前力量传给客户端
- PLAYER_ATTRIBUTE_SYNC sSync;
- sSync.ProtocolType = s2c_playersyncattribute;
- sSync.m_btAttribute = 1;
- sSync.m_nBasePoint = m_nDexterity;
- sSync.m_nCurPoint = m_nCurDexterity;
- sSync.m_nLeavePoint = m_nAttributePoint;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:增加基本活力
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseVitality(int nData)
- {
- if (nData > 0 && nData <= m_nAttributePoint)
- {
- m_nVitality += nData;
- m_nAttributePoint -= nData;
- m_nCurVitality += nData;
-
- 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();
-
- // 把当前力量传给客户端
- PLAYER_ATTRIBUTE_SYNC sSync;
- sSync.ProtocolType = s2c_playersyncattribute;
- sSync.m_btAttribute = 2;
- sSync.m_nBasePoint = m_nVitality;
- sSync.m_nCurPoint = m_nCurVitality;
- sSync.m_nLeavePoint = m_nAttributePoint;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
- }
- }
- #endif
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:增加基本精力
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseEngergy(int nData)
- {
- if (nData > 0 && nData <= m_nAttributePoint)
- {
- m_nEngergy += nData;
- m_nAttributePoint -= nData;
- m_nCurEngergy += nData;
-
- Npc[m_nIndex].AddBaseManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
- UpdataCurData();
-
- // 把当前力量传给客户端
- PLAYER_ATTRIBUTE_SYNC sSync;
- sSync.ProtocolType = s2c_playersyncattribute;
- sSync.m_btAttribute = 3;
- sSync.m_nBasePoint = m_nEngergy;
- sSync.m_nCurPoint = m_nCurEngergy;
- sSync.m_nLeavePoint = m_nAttributePoint;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
- }
- }
- #endif
- //-------------------------------------------------------------------------
- // 功能:改变当前力量(当 nData 小于 0 时,减少)
- //-------------------------------------------------------------------------
- void KPlayer::ChangeCurStrength(int nData)
- {
- /* if (m_nCurStrength + nData < m_nStrength)
- return;
- */
- m_nCurStrength += nData;
- SetNpcPhysicsDamage();
- // 把当前力量传给客户端
- }
- //-------------------------------------------------------------------------
- // 功能:改变当前敏捷(当 nData 小于 0 时,减少)
- //-------------------------------------------------------------------------
- void KPlayer::ChangeCurDexterity(int nData)
- {
- /* if (m_nCurDexterity + nData < 0)
- return;
- */
- m_nCurDexterity += nData;
-
- int nRating = nData * 4;
- Npc[m_nIndex].m_CurrentAttackRating += nRating;
-
- int nDefence = nData / 4;
- Npc[m_nIndex].m_CurrentDefend += nDefence;
-
- SetNpcPhysicsDamage();
-
- }
- //-------------------------------------------------------------------------
- // 功能:改变当前活力(当 nData 小于 0 时,减少)
- //-------------------------------------------------------------------------
- void KPlayer::ChangeCurVitality(int nData)
- {
- /* if (nData + m_nAttributePoint < 0)
- return;
- */
- m_nCurVitality += nData;
-
- Npc[m_nIndex].AddCurLifeMax(PlayerSet.m_cLevelAdd.GetLifePerVitality(Npc[m_nIndex].m_Series) * nData);
- Npc[m_nIndex].AddCurStaminaMax(PlayerSet.m_cLevelAdd.GetStaminaPerVitality(Npc[m_nIndex].m_Series) * nData);
-
- }
- //-------------------------------------------------------------------------
- // 功能:改变当前精力(当 nData 小于 0 时,减少)
- //-------------------------------------------------------------------------
- void KPlayer::ChangeCurEngergy(int nData)
- {
- /* if (m_nAttributePoint + nData < 0)
- return;
- */
- m_nCurEngergy += nData;
-
- Npc[m_nIndex].AddCurManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
-
- }
- //-------------------------------------------------------------------------
- // 功能:增加基本运气
- //-------------------------------------------------------------------------
- void KPlayer::AddBaseLucky(int nData)
- {
- m_nLucky += nData;
- CalcCurLucky();
- }
- //-------------------------------------------------------------------------
- // 功能:由当前力量计算对应npc的物理伤害(PhysicsDamage)
- //-------------------------------------------------------------------------
- void KPlayer::SetNpcPhysicsDamage()
- {
- int nMinDamage, nMaxDamage;
- m_ItemList.GetWeaponDamage(&nMinDamage, &nMaxDamage);
-
- if (m_ItemList.GetWeaponType() == equip_meleeweapon) // (当前装备是近身武器)
- {
- /* nMinDamage = nMinDamage * (m_nCurStrength + STRENGTH_SET_DAMAGE_VALUE) / STRENGTH_SET_DAMAGE_VALUE;
- nMaxDamage = nMaxDamage * (m_nCurStrength + STRENGTH_SET_DAMAGE_VALUE) / STRENGTH_SET_DAMAGE_VALUE;
- */
- // 数值计算方法修改(孙英要求) by Spe 03/06/11
- nMinDamage += m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE;
- nMaxDamage += m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE;
- Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
- }
- else if (m_ItemList.GetWeaponType() == equip_rangeweapon) // (当前装备是远程武器)
- {
- /* nMinDamage = nMinDamage * (m_nCurDexterity + DEXTERITY_SET_DAMAGE_VALUE) / DEXTERITY_SET_DAMAGE_VALUE;
- nMaxDamage = nMaxDamage * (m_nCurDexterity + DEXTERITY_SET_DAMAGE_VALUE) / DEXTERITY_SET_DAMAGE_VALUE;
- */
- // 数值计算方法修改(孙英要求) by Spe 03/06/11
- nMinDamage += m_nCurDexterity / DEXTERITY_SET_DAMAGE_VALUE;
- nMaxDamage += m_nCurDexterity / DEXTERITY_SET_DAMAGE_VALUE;
- Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
- }
- else
- {
- Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
- }
- }
- //-------------------------------------------------------------------------
- // 功能:由当前敏捷计算对应npc的攻击命中率(AttackRating)
- //-------------------------------------------------------------------------
- void KPlayer::SetNpcAttackRating()
- {
- int nRating;
-
- nRating = m_nDexterity * 4 - 28;
- Npc[m_nIndex].SetBaseAttackRating(nRating);
- }
- //-------------------------------------------------------------------------
- // 功能:由当前敏捷计算对应npc的防御力
- //-------------------------------------------------------------------------
- void KPlayer::SetNpcDefence()
- {
- int nDefence;
-
- nDefence = m_nDexterity / 4;
- Npc[m_nIndex].SetBaseDefence(nDefence);
- }
- /*
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:由当前敏捷计算对应npc的行走速度
- //-------------------------------------------------------------------------
- void KPlayer::SetNpcWalkSpeed()
- {
- int nSpeed;
- nSpeed = BASE_WALK_SPEED * (m_nCurDexterity + 320) / 320;
- Npc[m_nIndex].SetBaseWalkSpeed(nSpeed);
- }
- #endif
- */
- /*
- #ifdef _SERVER
- //-------------------------------------------------------------------------
- // 功能:由当前敏捷计算对应npc的跑步速度
- //-------------------------------------------------------------------------
- void KPlayer::SetNpcRunSpeed()
- {
- int nSpeed;
- nSpeed = BASE_RUN_SPEED * (m_nCurDexterity + 320) / 320;
- Npc[m_nIndex].SetBaseRunSpeed(nSpeed);
- }
- #endif
- */
- //-------------------------------------------------------------------------
- // 功能:增加经验(原始数据,还未经过处理,需要处理组队的影响)
- //-------------------------------------------------------------------------
- void KPlayer::AddExp(int nExp, int nTarLevel)
- {
- #ifndef _SERVER
- AddSelfExp(nExp, nTarLevel);
- #endif
-
- #ifdef _SERVER
- // 没有组队
- if ( !m_cTeam.m_nFlag )
- {
- AddSelfExp(nExp, nTarLevel);
- return;
- }
-
- // 已经组队
- int i, j, nShareFlag[MAX_TEAM_MEMBER + 1], nRegion, nTotalLevel = 0, nTotalPlayer = 0;
- memset(nShareFlag, 0, sizeof(nShareFlag));
-
- int nMpsX, nMpsY, nNpcIdx, nSelfSubIdx, nSelfMpsX, nSelfMpsY;
-
- nSelfSubIdx = Npc[m_nIndex].m_SubWorldIndex;
- SubWorld[nSelfSubIdx].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,
- &nSelfMpsX,
- &nSelfMpsY);
-
- // 队长
- nNpcIdx = Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex;
- if (nSelfSubIdx == Npc[nNpcIdx].m_SubWorldIndex)
- {
- SubWorld[Npc[nNpcIdx].m_SubWorldIndex].Map2Mps(
- Npc[nNpcIdx].m_RegionIndex,
- Npc[nNpcIdx].m_MapX,
- Npc[nNpcIdx].m_MapY,
- Npc[nNpcIdx].m_OffX,
- Npc[nNpcIdx].m_OffY,
- &nMpsX,
- &nMpsY);
- if ( (nMpsX - nSelfMpsX) * (nMpsX - nSelfMpsX) +
- (nMpsY - nSelfMpsY) * (nMpsY - nSelfMpsY) <=
- PLAYER_SHARE_EXP_DISTANCE * PLAYER_SHARE_EXP_DISTANCE)
- {
- nTotalLevel += Npc[nNpcIdx].m_Level;
- nShareFlag[0] = 1;
- nTotalPlayer++;
- if (nTotalPlayer >= g_Team[m_cTeam.m_nID].m_nMemNum + 1)
- goto SharePlace;
- }
- }
- // 队员
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] < 0)
- continue;
- nNpcIdx = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
- if (nSelfSubIdx != Npc[nNpcIdx].m_SubWorldIndex)
- continue;
- SubWorld[Npc[nNpcIdx].m_SubWorldIndex].Map2Mps(
- Npc[nNpcIdx].m_RegionIndex,
- Npc[nNpcIdx].m_MapX,
- Npc[nNpcIdx].m_MapY,
- Npc[nNpcIdx].m_OffX,
- Npc[nNpcIdx].m_OffY,
- &nMpsX,
- &nMpsY);
- if ( (nMpsX - nSelfMpsX) * (nMpsX - nSelfMpsX) +
- (nMpsY - nSelfMpsY) * (nMpsY - nSelfMpsY) >
- PLAYER_SHARE_EXP_DISTANCE * PLAYER_SHARE_EXP_DISTANCE)
- continue;
- nTotalLevel += Npc[nNpcIdx].m_Level;
- nShareFlag[i + 1] = 1;
- nTotalPlayer++;
- if (nTotalPlayer >= g_Team[m_cTeam.m_nID].m_nMemNum + 1)
- goto SharePlace;
- }
-
- SharePlace:
- _ASSERT(nTotalPlayer >= 1);
- _ASSERT(nTotalLevel >= 1);
- if (nTotalPlayer < 1 || nTotalLevel < 1)
- return;
- if (nTotalPlayer == 1)
- {
- AddSelfExp(nExp, nTarLevel);
- return;
- }
- int k, nGetExp;
- k = 100 + nTotalPlayer * 15;
-
-
- // 给队长分配经验
- if (nShareFlag[0])
- {
- nGetExp = k * Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].m_Level / nTotalLevel;
- if (nGetExp < 5)
- nGetExp = 5;
- Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // LeadExp = 怪物提供的经验值 * β * 分享者等级 / 分享者等级和;
- int nLeadExp = nExp * k * PlayerSet.m_cLevelAdd.GetLeadExpShare(Npc[m_nIndex].m_Series) * (nTotalLevel - Npc[m_nIndex].m_Level) / (nTotalLevel * 10000);
- Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddLeadExp(nLeadExp);
- // if (g_Team[m_cTeam.m_nID].m_nCaptain == m_nPlayerIndex)
- // {
- // if (nGetExp < 50)
- // nGetExp = 50;
- // Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // }
- // else
- // {
- // if (nGetExp < 5)
- // nGetExp = 5;
- // Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // }
- }
- // 给队员分配经验
- for (i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if ( !nShareFlag[i + 1] )
- continue;
- nGetExp = k * Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].m_Level / nTotalLevel;
- if (nGetExp < 5)
- nGetExp = 5;
- Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // if (g_Team[m_cTeam.m_nID].m_nMember[i] == m_nPlayerIndex)
- // {
- // if (nGetExp < 50)
- // nGetExp = 50;
- // Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // }
- // else
- // {
- // if (nGetExp < 5)
- // nGetExp = 5;
- // Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
- // }
- }
-
- #endif
- }
- //-------------------------------------------------------------------------
- // 功能:增加经验(不需要再经过队伍分配的处理)
- // nExp 增加的经验 nTarLevel 被打死的npc的等级
- // 详情参阅 sourcesafe策划库documentSystem战斗经验设定.doc
- //-------------------------------------------------------------------------
- void KPlayer::AddSelfExp(int nExp, int nTarLevel)
- {
- if (nExp <= 0)
- return;
- if (Npc[m_nIndex].m_Level >= MAX_LEVEL)
- return;
- if (Npc[m_nIndex].m_Doing == do_death || Npc[m_nIndex].m_Doing == do_revive)
- return;
- int nSubLevel, nGetExp;
- // int nAbsLevel;
- nSubLevel = Npc[m_nIndex].m_Level - nTarLevel;
- if (nSubLevel <= 5)
- {
- nGetExp = nExp;
- }
- else if (nSubLevel <= 15)
- {
- // nGetExp = nExp * (100 - (95 / 10) * (nSubLevel - 5)) / 100;
- nGetExp = nExp * (295 - 19 * nSubLevel) / 200;
- }
- else
- {
- nGetExp = nExp / 20;
- }
-
- /*
- nAbsLevel = abs(nTarLevel - Npc[m_nIndex].m_Level);
-
- if (nAbsLevel <= 10)
- {
- nGetExp = nExp;
- }
- else if (nAbsLevel <= 20)
- {
- nGetExp = nExp * (30 - nAbsLevel) / 20; // EXP=X*(150-|LM-LP|*5)/100
- }
- else
- {
- nGetExp = nExp / 2;
- }
- */
- if (nGetExp <= 0)
- nGetExp = 1;
-
- m_nExp += nGetExp;
- g_DebugLog("[数值]%s实际增加经验%d点", Npc[m_nIndex].Name, nGetExp);
- #ifdef _SERVER
- if (m_nExp >= m_nNextLevelExp) // 升级
- {
- LevelUp();
- }
- else // 同步经验
- {
- PLAYER_EXP_SYNC sSyncExp;
- sSyncExp.ProtocolType = (BYTE)s2c_playerexp;
- sSyncExp.m_nExp = m_nExp;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSyncExp, sizeof(PLAYER_EXP_SYNC));
- }
- #endif
- }
- //-------------------------------------------------------------------------
- // 功能:直接增加经验值,不考虑其他因素
- //-------------------------------------------------------------------------
- void KPlayer::DirectAddExp(int nExp)
- {
- if (nExp > 0 && Npc[m_nIndex].m_Level >= MAX_LEVEL)
- return;
-
- m_nExp += nExp;
- if (m_nExp < 0)
- {
- if (-m_nExp > m_nNextLevelExp)
- m_nExp = -m_nNextLevelExp;
- }
- #ifdef _SERVER
- if (m_nExp >= m_nNextLevelExp) // 升级
- {
- LevelUp();
- }
- else // 同步经验
- {
- PLAYER_EXP_SYNC sSyncExp;
- sSyncExp.ProtocolType = (BYTE)s2c_playerexp;
- sSyncExp.m_nExp = m_nExp;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSyncExp, sizeof(PLAYER_EXP_SYNC));
- }
- #endif
- }
- //-------------------------------------------------------------------------
- // 功能:玩家升一级
- //-------------------------------------------------------------------------
- void KPlayer::LevelUp()
- {
- m_nExp = 0;
- if (Npc[m_nIndex].m_Level >= MAX_LEVEL)
- return;
- Npc[m_nIndex].m_Level++;
- m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level);
-
- // -------------------------- 等级增加时各项属性增加 ----------------------
- // 增加未分配属性点
- m_nAttributePoint += PLAYER_LEVEL_ADD_ATTRIBUTE;
- // 增加未分配技能点
- m_nSkillPoint += PLAYER_LEVEL_ADD_SKILL;
-
- // 处理生命、体力、内力值(影响基本生命、体力、内力最大值的因素:等级、属性点,影响当前生命最大值的因素:装备、技能、药物(临时))
- LevelAddBaseLifeMax();
- LevelAddBaseStaminaMax();
- LevelAddBaseManaMax();
- // Npc[m_nIndex].ResetLifeReplenish();
-
- // 处理各种抗性的变化 火、冰、毒、电、物理
- 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;
-
- #ifdef _SERVER
- // 给客户端发送数据
- // 自己的数据
- PLAYER_LEVEL_UP_SYNC sLevelUp;
- sLevelUp.ProtocolType = s2c_playerlevelup;
- sLevelUp.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
- sLevelUp.m_nExp = m_nExp;
- sLevelUp.m_nAttributePoint = m_nAttributePoint;
- sLevelUp.m_nSkillPoint = m_nSkillPoint;
- sLevelUp.m_nBaseLifeMax = Npc[m_nIndex].m_LifeMax;
- sLevelUp.m_nBaseStaminaMax = Npc[m_nIndex].m_StaminaMax;
- sLevelUp.m_nBaseManaMax = Npc[m_nIndex].m_ManaMax;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLevelUp, sizeof(PLAYER_LEVEL_UP_SYNC));
- // 给队友发送等级数据
- if ( m_cTeam.m_nFlag )
- {
- PLAYER_TEAMMATE_LEVEL_SYNC sLevel;
- sLevel.ProtocolType = s2c_teammatelevel;
- sLevel.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
- sLevel.m_dwTeammateID = Npc[m_nIndex].m_dwID;
- // 给队长发
- if (m_cTeam.m_nFigure != TEAM_CAPTAIN)
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_TEAMMATE_LEVEL_SYNC));
- for (int i = 0; i < MAX_TEAM_MEMBER; i++)
- {
- if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0 && g_Team[m_cTeam.m_nID].m_nMember[i] != GetPlayerIndex())
- g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_TEAMMATE_LEVEL_SYNC));
- }
- }
- #endif
- }
- // need spe edit not end
- void KPlayer::UpdataCurData()
- {
- if (m_nIndex <= 0 || m_nIndex >= MAX_NPC)
- return;
-
- Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
- Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
- Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
- Npc[m_nIndex].m_CurrentAttackRating = Npc[m_nIndex].m_AttackRating;
- Npc[m_nIndex].m_CurrentAttackSpeed = Npc[m_nIndex].m_AttackSpeed;
- // Npc[m_nIndex].m_CurrentCamp = Npc[m_nIndex].m_Camp;
- Npc[m_nIndex].m_CurrentCastSpeed = Npc[m_nIndex].m_CastSpeed;
- ZeroMemory(&Npc[m_nIndex].m_CurrentColdDamage, sizeof(KMagicAttrib));
- Npc[m_nIndex].m_CurrentColdEnhance = 0;
- Npc[m_nIndex].m_CurrentColdResist = Npc[m_nIndex].m_ColdResist;
- Npc[m_nIndex].m_CurrentColdResistMax = Npc[m_nIndex].m_ColdResistMax;
- Npc[m_nIndex].m_CurrentDamage2Mana = 0;
- Npc[m_nIndex].m_CurrentDamageReduce = 0;
- Npc[m_nIndex].m_CurrentDeadlyStrike = 0;
- Npc[m_nIndex].m_CurrentDefend = Npc[m_nIndex].m_Defend;
- Npc[m_nIndex].m_CurrentElementDamageReduce = 0;
- ZeroMemory(&Npc[m_nIndex].m_CurrentFireDamage, sizeof(KMagicAttrib));
- Npc[m_nIndex].m_CurrentFireEnhance = 0;
- Npc[m_nIndex].m_CurrentFireResist = Npc[m_nIndex].m_FireResist;
- Npc[m_nIndex].m_CurrentFireResistMax = Npc[m_nIndex].m_FireResistMax;
- Npc[m_nIndex].m_CurrentHandEnhance = 0;
- Npc[m_nIndex].m_CurrentHitRecover = Npc[m_nIndex].m_HitRecover;
- Npc[m_nIndex].m_CurrentJumpSpeed = Npc[m_nIndex].m_JumpSpeed;
- Npc[m_nIndex].m_CurrentKnockBack = 0;
- Npc[m_nIndex].m_CurrentLifeReplenish = Npc[m_nIndex].m_LifeReplenish;
- Npc[m_nIndex].m_CurrentLifeStolen = 0;
- ZeroMemory(&Npc[m_nIndex].m_CurrentLightDamage, sizeof(KMagicAttrib));
- Npc[m_nIndex].m_CurrentLightEnhance = 0;
- Npc[m_nIndex].m_CurrentLightResist = Npc[m_nIndex].m_LightResist;
- Npc[m_nIndex].m_CurrentLightResistMax = Npc[m_nIndex].m_LightResistMax;
- Npc[m_nIndex].m_CurrentManaPerEnemy = 0;
- Npc[m_nIndex].m_CurrentManaReplenish = Npc[m_nIndex].m_ManaReplenish;
- Npc[m_nIndex].m_CurrentManaStolen = 0;
- Npc[m_nIndex].m_CurrentMeleeDmgRet = 0;
- Npc[m_nIndex].m_CurrentMeleeDmgRetPercent = 0;
- ZeroMemory(&Npc[m_nIndex].m_CurrentMeleeEnhance, sizeof(Npc[m_nIndex].m_CurrentMeleeEnhance));
- Npc[m_nIndex].m_CurrentPhysicsResist = Npc[m_nIndex].m_PhysicsResist;
- Npc[m_nIndex].m_CurrentPhysicsResistMax = Npc[m_nIndex].m_PhysicsResistMax;
- Npc[m_nIndex].m_CurrentPiercePercent = 0;
- ZeroMemory(&Npc[m_nIndex].m_CurrentPoisonDamage, sizeof(KMagicAttrib));
- Npc[m_nIndex].m_CurrentPoisonEnhance = 0;
- Npc[m_nIndex].m_CurrentPoisonResist = Npc[m_nIndex].m_PoisonResist;
- Npc[m_nIndex].m_CurrentPoisonResistMax = Npc[m_nIndex].m_PoisonResistMax;
- Npc[m_nIndex].m_CurrentRangeDmgRet = 0;
- Npc[m_nIndex].m_CurrentRangeDmgRetPercent = 0;
- Npc[m_nIndex].m_CurrentRangeEnhance = 0;
- Npc[m_nIndex].m_CurrentRunSpeed = Npc[m_nIndex].m_RunSpeed;
- Npc[m_nIndex].m_CurrentSlowMissle = 0;
- Npc[m_nIndex].m_CurrentStaminaGain = Npc[m_nIndex].m_StaminaGain;
- Npc[m_nIndex].m_CurrentStaminaLoss = Npc[m_nIndex].m_StaminaLoss;
- Npc[m_nIndex].m_CurrentStaminaStolen = 0;
- Npc[m_nIndex].m_CurrentVisionRadius = Npc[m_nIndex].m_VisionRadius;
- Npc[m_nIndex].m_CurrentWalkSpeed = Npc[m_nIndex].m_WalkSpeed;
- Npc[m_nIndex].m_CurrentAddPhysicsDamage = 0;
- m_nCurStrength = m_nStrength;
- m_nCurDexterity = m_nDexterity;
- m_nCurVitality = m_nVitality;
- m_nCurEngergy = m_nEngergy;
- m_nCurLucky = m_nLucky;
-
- ReCalcEquip();
- ReCalcState();
- }
- void KPlayer::ReCalcEquip()
- {
- _ASSERT(m_nIndex > 0 && m_nIndex < MAX_NPC);
-
- for (int i = 0; i < itempart_num; i++)
- {
- int nIdx = m_ItemList.m_EquipItem[i];
- if (!nIdx)
- continue;
- int nActive = m_ItemList.GetEquipEnhance(i);
- Item[nIdx].ApplyMagicAttribToNPC(&Npc[m_nIndex], nActive);
- }
- }
- void KPlayer::ReCalcState()
- {
- _ASSERT(m_nIndex > 0 && m_nIndex < MAX_NPC);
-
- Npc[m_nIndex].ReCalcStateEffect();
- }
- //-------------------------------------------------------------------------
- // 功能:增加统率力经验
- //-------------------------------------------------------------------------
- void KPlayer::AddLeadExp(int nExp)
- {
- if (m_dwLeadLevel >= MAX_LEAD_LEVEL)
- return;
- if (Npc[m_nIndex].m_Doing == do_death || Npc[m_nIndex].m_Doing == do_revive)
- return;
- m_dwLeadExp += nExp;
- if (m_dwLeadExp >= (DWORD)PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel))
- {
- // 升级
- m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(m_dwLeadExp, m_dwLeadLevel);
- #ifndef _SERVER
- m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel);
- #endif
- }
-
- #ifdef _SERVER
- PLAYER_LEAD_EXP_SYNC sLeadExp;
- sLeadExp.ProtocolType = s2c_playersyncleadexp;
- sLeadExp.m_dwLeadExp = m_dwLeadExp;
- g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeadExp, sizeof(PLAYER_LEAD_EXP_SYNC));
- #endif
-
- }
- //-------------------------------------------------------------------------
- // 功能:玩家升一级加生命
- //-------------------------------------------------------------------------
- void KPlayer::LevelAddBaseLifeMax()
- {
- Npc[m_nIndex].m_LifeMax += PlayerSet.m_cLevelAdd.GetLifePerLevel(Npc[m_nIndex].m_Series);
- Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
- }
- //-------------------------------------------------------------------------
- // 功能:玩家升一级加体力
- //-------------------------------------------------------------------------
- void KPlayer::LevelAddBaseStaminaMax()
- {
- Npc[m_nIndex].m_StaminaMax += PlayerSet.m_cLevelAdd.GetStaminaPerLevel(Npc[m_nIndex].m_Series);
- Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
- }
- //-------------------------------------------------------------------------
- // 功能:玩家升一级加内力
- //-------------------------------------------------------------------------
- void KPlayer::LevelAddBaseManaMax()
- {
- Npc[m_nIndex].m_ManaMax += PlayerSet.m_cLevelAdd.GetManaPerLevel(Npc[m_nIndex].m_Series);
- Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
- }
- //-------------------------------------------------------------------------
- // 功能:改变玩家阵营
- //-------------------------------------------------------------------------
- void KPlayer::ChangePlayerCamp(int nCamp)
- {
- if (nCamp < camp_begin || nCamp >= camp_num)
- return;
- Npc[m_nIndex].m_Camp = (NPCCAMP)nCamp;
- }
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:向服务器申请查询某个npc所在队伍的信息
- //-------------------------------------------------------------------------
- void KPlayer::ApplyTeamInfo(DWORD dwNpcID)
- {
- if (dwNpcID <= 0)
- return;
- PLAYER_APPLY_TEAM_INFO sApplyInfo;
- sApplyInfo.ProtocolType = (BYTE)c2s_teamapplyinfo;
- sApplyInfo.m_dwTarNpcID = dwNpcID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sApplyInfo, sizeof(PLAYER_APPLY_TEAM_INFO));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:向服务器申请查询玩家自身的队伍情况
- //-------------------------------------------------------------------------
- void KPlayer::ApplySelfTeamInfo()
- {
- ApplyTeamInfo(Npc[m_nIndex].m_dwID);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家向服务器申请创建队伍
- //-------------------------------------------------------------------------
- BOOL KPlayer::ApplyCreateTeam()//char *lpszTeamName)
- {
- return m_cTeam.ApplyCreate();//lpszTeamName);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长向服务器申请开放、关闭队伍是否允许加入成员状态
- //-------------------------------------------------------------------------
- BOOL KPlayer::ApplyTeamOpenClose(BOOL bFlag)
- {
- if ( !m_cTeam.m_nFlag ) // 未组队
- return FALSE;
- if (m_cTeam.m_nFigure != TEAM_CAPTAIN) // 不是队长
- return FALSE;
- if (this->CheckTrading()) // 处在交易状态
- return FALSE;
-
- if (bFlag)
- {
- if (PlayerSet.m_cLeadExp.GetMemNumFromLevel(m_dwLeadLevel) <= g_Team[0].m_nMemNum) // 统帅力不够
- return FALSE;
- }
-
- PLAYER_TEAM_OPEN_CLOSE sTeamState;
- sTeamState.ProtocolType = c2s_teamapplyopenclose;
- sTeamState.m_btOpenClose = bFlag;
- if (g_pClient)
- g_pClient->SendPackToServer(&sTeamState, sizeof(PLAYER_TEAM_OPEN_CLOSE));
- return TRUE;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家向服务器申请加入某个队伍
- // 参数:int nNpcIndex 目标队伍队长在客户端Npc数组中的位置
- //-------------------------------------------------------------------------
- void KPlayer::ApplyAddTeam(int nNpcIndex)
- {
- if (this->CheckTrading())
- return;
- if (m_cTeam.m_nFlag) // 已经组队,不能申请加入别的队伍
- return;
-
- // 不同阵营现在可以组队,老手不能加入新人队伍,新人可以加入老手队伍
- if (Npc[nNpcIndex].m_Camp == camp_begin && Npc[m_nIndex].m_Camp != camp_begin)
- return;
- // if (Npc[nNpcIndex].m_Camp != Npc[m_nIndex].m_Camp) // 阵营不同
- // return;
-
- // 判断目标队伍队长是不是处在队伍开放状态
- if (Npc[nNpcIndex].GetMenuState() != PLAYER_MENU_STATE_TEAMOPEN)
- return;
-
- m_cTeam.m_nApplyCaptainID = Npc[nNpcIndex].m_dwID;
- m_cTeam.m_dwApplyTimer = MAX_APPLY_TEAM_TIME;
- PLAYER_APPLY_ADD_TEAM sAddTeam;
- sAddTeam.ProtocolType = c2s_teamapplyadd;
- sAddTeam.m_dwTarNpcID = Npc[nNpcIndex].m_dwID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sAddTeam, sizeof(PLAYER_APPLY_ADD_TEAM));
-
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TEAM_APPLY_ADD_SELF_MSG, Npc[nNpcIndex].Name);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家通知服务器接受某个npc为队伍成员
- //-------------------------------------------------------------------------
- void KPlayer::AcceptTeamMember(DWORD dwNpcID)
- {
- // 判断状态 (缺少对npc队伍开放状态的检测 not end)
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- {
- ApplySelfTeamInfo();
- return;
- }
- if (dwNpcID == 0)
- return;
-
- // 查找申请列表
- int i;
- for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
- {
- if (m_cTeam.m_sApplyList[i].m_dwNpcID == dwNpcID)
- {
- m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
- m_cTeam.UpdateInterface();
- break;
- }
- }
- // 如果没找到
- // if (i >= MAX_TEAM_APPLY_LIST)
- // return;
-
- // 向服务器发申请
- PLAYER_ACCEPT_TEAM_MEMBER sAcceptTeam;
- sAcceptTeam.ProtocolType = c2s_teamacceptmember;
- sAcceptTeam.m_dwNpcID = dwNpcID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sAcceptTeam, sizeof(PLAYER_ACCEPT_TEAM_MEMBER));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长删除加入队伍申请列表中的某个npc
- //-------------------------------------------------------------------------
- void KPlayer::TeamDropApplyOne(DWORD dwNpcID)
- {
- if (dwNpcID == 0)
- return;
- // 查找申请列表
- int i;
- for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
- {
- if (m_cTeam.m_sApplyList[i].m_dwNpcID == dwNpcID)
- {
- m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
- m_cTeam.m_sApplyList[i].m_dwTimer = 0;
- m_cTeam.m_sApplyList[i].m_nLevel = 0;
- m_cTeam.m_sApplyList[i].m_szName[0] = 0;
- break;
- }
- }
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:通知服务器本玩家离开队伍
- //-------------------------------------------------------------------------
- void KPlayer::LeaveTeam()
- {
- PLAYER_APPLY_LEAVE_TEAM sLeaveTeam;
- sLeaveTeam.ProtocolType = c2s_teamapplyleave;
- if (g_pClient)
- g_pClient->SendPackToServer(&sLeaveTeam, sizeof(PLAYER_APPLY_LEAVE_TEAM));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长通知服务器踢除某个队员
- //-------------------------------------------------------------------------
- void KPlayer::TeamKickMember(DWORD dwNpcID)
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
-
- PLAYER_TEAM_KICK_MEMBER sKickOne;
- sKickOne.ProtocolType = c2s_teamapplykickmember;
- sKickOne.m_dwNpcID = dwNpcID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sKickOne, sizeof(PLAYER_TEAM_KICK_MEMBER));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长向服务器申请把自己的队长身份交给别的队员
- //-------------------------------------------------------------------------
- void KPlayer::ApplyTeamChangeCaptain(DWORD dwNpcID)
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
-
- PLAYER_APPLY_TEAM_CHANGE_CAPTAIN sTeamChange;
- sTeamChange.ProtocolType = c2s_teamapplychangecaptain;
- sTeamChange.m_dwNpcID = dwNpcID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sTeamChange, sizeof(PLAYER_APPLY_TEAM_CHANGE_CAPTAIN));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长向服务器申请解散队伍
- //-------------------------------------------------------------------------
- void KPlayer::ApplyTeamDismiss()
- {
- if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
- return;
-
- PLAYER_APPLY_TEAM_DISMISS sTeamDismiss;
- sTeamDismiss.ProtocolType = c2s_teamapplydismiss;
- if (g_pClient)
- g_pClient->SendPackToServer(&sTeamDismiss, sizeof(PLAYER_APPLY_TEAM_DISMISS));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家向服务器申请打开、关闭pk开关
- //-------------------------------------------------------------------------
- void KPlayer::ApplySetPK(BOOL bPK)
- {
- PLAYER_SET_PK sPK;
- sPK.ProtocolType = c2s_playerapplysetpk;
- sPK.m_btPKFlag = bPK;
- if (g_pClient)
- g_pClient->SendPackToServer(&sPK, sizeof(PLAYER_SET_PK));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:玩家向服务器申请门派数据
- //-------------------------------------------------------------------------
- void KPlayer::ApplyFactionData()
- {
- PLAYER_APPLY_FACTION_DATA sFaction;
- sFaction.ProtocolType = c2s_playerapplyfactiondata;
- if (g_pClient)
- g_pClient->SendPackToServer(&sFaction, sizeof(PLAYER_APPLY_FACTION_DATA));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:客户端发送聊天语句给服务器
- //-------------------------------------------------------------------------
- void KPlayer::SendChat(KUiMsgParam *pMsg, char *lpszSentence)
- {
- if (!lpszSentence || !pMsg || pMsg->nMsgLength <= 0)
- return;
- int nLength = pMsg->nMsgLength;
- if (nLength >= MAX_SENTENCE_LENGTH)
- nLength = MAX_SENTENCE_LENGTH - 1;
-
- if (pMsg->eGenre == MSG_G_CHAT)
- {
- Npc[m_nIndex].SetChatInfo(pMsg->szName, lpszSentence, nLength);
-
- m_cChat.SendSentence(pMsg, Npc[m_nIndex].m_szChatBuffer);
- }
- else if (pMsg->eGenre == MSG_G_CMD) // not end
- {
- }
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:队长向服务器申请增加四项属性中某一项的点数(0=Strength 1=Dexterity 2=Vitality 3=Engergy)
- //-------------------------------------------------------------------------
- void KPlayer::ApplyAddBaseAttribute(int nAttribute, int nNo)
- {
- if (nAttribute < 0 || nAttribute > 3)
- return;
- if (nNo <= 0 || nNo >= 255)
- return;
- PLAYER_ADD_BASE_ATTRIBUTE_COMMAND sAdd;
- sAdd.ProtocolType = c2s_playeraddbaseattribute;
- sAdd.m_btAttribute = nAttribute;
- sAdd.m_nAddNo = nNo;
- if (g_pClient)
- g_pClient->SendPackToServer(&sAdd, sizeof(PLAYER_ADD_BASE_ATTRIBUTE_COMMAND));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:向服务器申请某个技能升级
- //-------------------------------------------------------------------------
- BOOL KPlayer::ApplyAddSkillLevel(int nSkillID, int nAddPoint)
- {
- if ( !Npc[m_nIndex].m_SkillList.FindSame(nSkillID) )
- return FALSE;
- if (m_nSkillPoint < nAddPoint || nAddPoint + Npc[m_nIndex].m_SkillList.GetLevel(nSkillID) > MAX_SKILLLEVEL)
- return FALSE;
-
- PLAYER_ADD_SKILL_POINT_COMMAND sSkill;
- sSkill.ProtocolType = c2s_playerapplyaddskillpoint;
- sSkill.m_nSkillID = nSkillID;
- sSkill.m_nAddPoint = nAddPoint;
-
- if (g_pClient)
- g_pClient->SendPackToServer(&sSkill, sizeof(PLAYER_ADD_SKILL_POINT_COMMAND));
-
- return TRUE;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:向服务器申请使用某个物品(鼠标右键点击该物品,只能用于吃药)
- //-------------------------------------------------------------------------
- BOOL KPlayer::ApplyUseItem(int nItemID, ItemPos SrcPos)
- {
- if (this->CheckTrading())
- return FALSE;
- int nRet = m_ItemList.UseItem(nItemID);
- if (nRet == 0)
- return FALSE;
-
- if (nRet == REQUEST_EQUIP_ITEM)
- {
- }
- else if (nRet == REQUEST_EAT_MEDICINE)
- {
- PLAYER_EAT_ITEM_COMMAND sEat;
- sEat.ProtocolType = c2s_playereatitem;
- sEat.m_nItemID = nItemID;
- sEat.m_btPlace = SrcPos.nPlace;
- sEat.m_btX = SrcPos.nX;
- sEat.m_btY = SrcPos.nY;
- if (g_pClient)
- g_pClient->SendPackToServer(&sEat, sizeof(PLAYER_EAT_ITEM_COMMAND));
- }
-
- return TRUE;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:客户端鼠标点击obj检起某个物品,向服务器发消息
- //-------------------------------------------------------------------------
- void KPlayer::PickUpObj(int nObjIndex)
- {
- if (this->CheckTrading())
- return;
- if (nObjIndex <= 0)
- return;
- if (Object[nObjIndex].m_nKind != Obj_Kind_Item && Object[nObjIndex].m_nKind != Obj_Kind_Money)
- return;
-
- PLAYER_PICKUP_ITEM_COMMAND sPickUp;
- if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
- {
- sPickUp.ProtocolType = c2s_playerpickupitem;
- sPickUp.m_nObjID = Object[nObjIndex].m_nID;
- sPickUp.m_btPosType = 0;
- sPickUp.m_btPosX = 0;
- sPickUp.m_btPosY = 0;
- }
- else
- {
- ItemPos sItemPos;
- if ( FALSE == m_ItemList.SearchPosition(Object[nObjIndex].m_nItemWidth, Object[nObjIndex].m_nItemHeight, &sItemPos) )
- {
- KSystemMessage sMsg;
-
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.eType = SMT_NORMAL;
- sMsg.byParamSize = 0;
- sMsg.byPriority = 0;
-
- strcpy(sMsg.szMessage, MSG_SHOP_NO_ROOM);
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- return;
- }
- sPickUp.ProtocolType = c2s_playerpickupitem;
- sPickUp.m_nObjID = Object[nObjIndex].m_nID;
- sPickUp.m_btPosType = sItemPos.nPlace;
- sPickUp.m_btPosX = sItemPos.nX;
- sPickUp.m_btPosY = sItemPos.nY;
- }
-
- if (g_pClient)
- g_pClient->SendPackToServer(&sPickUp, sizeof(PLAYER_PICKUP_ITEM_COMMAND));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:客户端鼠标点击obj,向服务器发消息
- //-------------------------------------------------------------------------
- void KPlayer::ObjMouseClick(int nObjIndex)
- {
- if (this->CheckTrading())
- return;
- if (nObjIndex <= 0)
- return;
- if (Object[nObjIndex].m_nKind != Obj_Kind_Box && Object[nObjIndex].m_nKind != Obj_Kind_Prop)
- return;
- SendObjMouseClick(Object[nObjIndex].m_nID, SubWorld[0].m_Region[Object[nObjIndex].m_nRegionIdx].m_RegionID);
- }
- #endif
- #ifndef _SERVER
- // DownPos 是面板上的物品的当前坐标,UpPos 必须是手上物品放到面板上的坐标
- void KPlayer::MoveItem(ItemPos DownPos, ItemPos UpPos)
- {
- if (this->CheckTrading() && DownPos.nPlace == pos_traderoom)
- {
- if (this->m_cTrade.m_nTradeLock)
- return;
-
- // 任务物品的限制
- int nHandIdx = m_ItemList.Hand();
- if (nHandIdx && Item[nHandIdx].GetGenre() == item_task)
- {
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TRADE_TASK_ITEM);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- return;
- }
- }
-
- if (!CheckTrading() && DownPos.nPlace == pos_immediacy)
- {
- int nHandIdx = m_ItemList.Hand();
- if (nHandIdx)
- {
- if (m_ItemList.m_Room[room_immediacy].CheckSameDetailType(Item[nHandIdx].GetGenre(), Item[nHandIdx].GetDetailType()))
- {
- KSystemMessage sMsg;
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- sprintf(sMsg.szMessage, MSG_ITEM_SAME_DETAIL_IN_IMMEDIATE);
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- return;
- }
- }
- }
-
- SendClientCmdMoveItem(&DownPos, &UpPos);
- }
- #endif
- #ifndef _SERVER
- int KPlayer::ThrowAwayItem()
- {
- if (this->CheckTrading())
- return 0;
- if ( !m_ItemList.Hand() )
- return 0;
-
- PLAYER_THROW_AWAY_ITEM_COMMAND sThrow;
-
- sThrow.ProtocolType = c2s_playerthrowawayitem;
-
- if (g_pClient)
- g_pClient->SendPackToServer(&sThrow, sizeof(PLAYER_THROW_AWAY_ITEM_COMMAND));
-
- return 1;
- }
- #endif
- #ifndef _SERVER
- void KPlayer::ChatAddFriend(int nPlayerIdx)
- {
- CHAT_ADD_FRIEND_COMMAND sAdd;
- sAdd.ProtocolType = c2s_chataddfriend;
- sAdd.m_nTargetPlayerIdx = nPlayerIdx;
- if (g_pClient)
- g_pClient->SendPackToServer(&sAdd, sizeof(CHAT_ADD_FRIEND_COMMAND));
- }
- #endif
- #ifndef _SERVER
- void KPlayer::ChatRefuseFriend(int nPlayerIdx)
- {
- CHAT_REFUSE_FRIEND_COMMAND sRefuse;
- sRefuse.ProtocolType = c2s_chatrefusefriend;
- sRefuse.m_nTargetPlayerIdx = nPlayerIdx;
- if (g_pClient)
- g_pClient->SendPackToServer(&sRefuse, sizeof(CHAT_REFUSE_FRIEND_COMMAND));
- }
- #endif
- #ifndef _SERVER
- void KPlayer::TradeApplyOpen(char *lpszSentence, int nLength)
- {
- if (this->CheckTrading())
- return;
- if (!lpszSentence)
- nLength = 0;
- TRADE_APPLY_OPEN_COMMAND sOpen;
- sOpen.ProtocolType = c2s_tradeapplystateopen;
- if (nLength >= MAX_SENTENCE_LENGTH)
- nLength = MAX_SENTENCE_LENGTH - 1;
- sOpen.m_wLength = sizeof(TRADE_APPLY_OPEN_COMMAND) - 1 - sizeof(sOpen.m_szSentence) + nLength;
- memset(m_cMenuState.m_szSentence, 0, sizeof(m_cMenuState.m_szSentence));
- if (lpszSentence)
- memcpy(m_cMenuState.m_szSentence, lpszSentence, nLength);
- memset(sOpen.m_szSentence, 0, sizeof(sOpen.m_szSentence));
- memcpy(sOpen.m_szSentence, m_cMenuState.m_szSentence, nLength);
- if (g_pClient)
- g_pClient->SendPackToServer(&sOpen, sOpen.m_wLength + 1);
- }
- #endif
- #ifndef _SERVER
- void KPlayer::TradeApplyClose()
- {
- TRADE_APPLY_CLOSE_COMMAND sApply;
- sApply.ProtocolType = c2s_tradeapplystateclose;
- if (g_pClient)
- g_pClient->SendPackToServer(&sApply, sizeof(TRADE_APPLY_CLOSE_COMMAND));
- }
- #endif
- #ifndef _SERVER
- void KPlayer::TradeApplyStart(int nNpcIdx)
- {
- if (nNpcIdx < 0 || nNpcIdx >= MAX_NPC)
- return;
- TRADE_APPLY_START_COMMAND sStart;
- sStart.ProtocolType = c2s_tradeapplystart;
- sStart.m_dwID = Npc[nNpcIdx].m_dwID;
- if (g_pClient)
- g_pClient->SendPackToServer(&sStart, sizeof(TRADE_APPLY_START_COMMAND));
-
- KSystemMessage sMsg;
- sprintf(sMsg.szMessage, MSG_TRADE_SEND_APPLY, Npc[nNpcIdx].Name);
- sMsg.eType = SMT_NORMAL;
- sMsg.byConfirmType = SMCT_NONE;
- sMsg.byPriority = 0;
- sMsg.byParamSize = 0;
- CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
- }
- #endif
- #ifndef _SERVER
- BOOL KPlayer::TradeMoveMoney(int nMoney)
- {
- if (!CheckTrading())
- return FALSE;
- if (this->m_cTrade.m_nTradeLock)
- return FALSE;
- // 钱数量错误
- if (nMoney < 0 || nMoney > m_ItemList.GetEquipmentMoney())
- return FALSE;
-
- TRADE_MOVE_MONEY_COMMAND sMoney;
-
- sMoney.ProtocolType = c2s_trademovemoney;
- sMoney.m_nMoney = nMoney;
- if (g_pClient)
- g_pClient->SendPackToServer(&sMoney, sizeof(TRADE_MOVE_MONEY_COMMAND));
-
- return TRUE;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:交易确定或取消
- // if nDecision == 0 推出交易 if nDecision == 1 确定交易 if nDecision == 2 取消交易确定
- //-------------------------------------------------------------------------
- void KPlayer::TradeDecision(int nDecision)
- {
- if ( !CheckTrading() )
- return;
- TRADE_DECISION_COMMAND sDecision;
- sDecision.ProtocolType = c2s_tradedecision;
- if (nDecision == 1)
- {
- sDecision.m_btDecision = 1;
- }
- else if (nDecision == 0)
- {
- sDecision.m_btDecision = 0;
- }
- else if (nDecision == 2)
- {
- sDecision.m_btDecision = 4;
- }
- if (g_pClient)
- g_pClient->SendPackToServer(&sDecision, sizeof(TRADE_DECISION_COMMAND));
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:交易锁定或取消锁定
- //-------------------------------------------------------------------------
- void KPlayer::TradeApplyLock(int nLockOrNot)
- {
- if ( !CheckTrading() )
- return;
- TRADE_DECISION_COMMAND sDecision;
- sDecision.ProtocolType = c2s_tradedecision;
- if (nLockOrNot)
- {
- sDecision.m_btDecision = 2;