KNpc.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:142k
- return FALSE;
- }
- else
- {
- if (!bOnlyCheckCanCast)
- *pSource -= nCost;
- return TRUE;
- }
- }
- return FALSE;
- }
- void KNpc::DoJump()
- {
- _ASSERT(m_RegionIndex >= 0);
- if (m_RegionIndex < 0)
- return;
- if (m_Doing == do_jump)
- return;
-
- m_Doing = do_jump;
- m_Dir = m_JumpDir;
- m_ProcessAI = 0;
- m_JumpFirstSpeed = ACCELERATION_OF_GRAVITY * (m_JumpStep - 1) / 2 ;
- #ifdef _SERVER // 向周围9个Region广播发技能
- NPC_JUMP_SYNC NetCommand;
- NetCommand.ProtocolType = (BYTE)s2c_npcjump;
- NetCommand.ID = m_dwID;
- NetCommand.nMpsX = m_DesX;
- NetCommand.nMpsY = m_DesY;
-
- POINT POff[8] =
- {
- {0, 32},
- {-16, 32},
- {-16, 0},
- {-16, -32},
- {0, -32},
- {16, -32},
- {16, 0},
- {16, 32},
- };
- int nMaxCount = MAX_BROADCAST_COUNT;
- CURREGION.BroadCast(&NetCommand, sizeof(NetCommand), nMaxCount, m_MapX, m_MapY);
- for (int i= 0; i < 8; i++)
- {
- if (CONREGIONIDX(i) == -1)
- continue;
- CONREGION(i).BroadCast(&NetCommand, sizeof(NetCommand), nMaxCount, m_MapX - POff[i].x, m_MapY - POff[i].y);
- }
- #endif
- #ifndef _SERVER
- m_ClientDoing = cdo_jump;
- #endif
- m_Frames.nTotalFrame = m_JumpStep;
- m_Frames.nCurrentFrame = 0;
- }
- BOOL KNpc::OnJump()
- {
- ServeJump(m_CurrentJumpSpeed);
- if (WaitForFrame())
- {
- DoStand();
- m_ProcessAI = 1;
- return FALSE;
- }
- return TRUE;
- }
- BOOL KNpc::WaitForFrame()
- {
- m_Frames.nCurrentFrame++;
- if (m_Frames.nCurrentFrame < m_Frames.nTotalFrame)
- {
- return FALSE;
- }
- m_Frames.nCurrentFrame = 0;
- return TRUE;
- }
- BOOL KNpc::IsReachFrame(int nPercent)
- {
- if (m_Frames.nCurrentFrame == m_Frames.nTotalFrame * nPercent / 100)
- {
- return TRUE;
- }
- return FALSE;
- }
- //客户端从网络得到的NpcSettingIdx是包含高16位Npc的模板号与低16位为等级
- void KNpc::Load(int nNpcSettingIdx, int nLevel)
- {
- m_PathFinder.Init(m_Index);
- if (nLevel <= 0)
- {
- nLevel = 1;
- }
- #ifndef _SERVER
- char szNpcTypeName[32];
- #endif
- if (nNpcSettingIdx == PLAYER_MALE_NPCTEMPLATEID || nNpcSettingIdx == PLAYER_FEMALE_NPCTEMPLATEID)
- {
- m_NpcSettingIdx = nNpcSettingIdx;
- m_Level = nLevel;
- #ifndef _SERVER
- if (nNpcSettingIdx == PLAYER_MALE_NPCTEMPLATEID)
- {
- strcpy(szNpcTypeName, "男主角");
- m_StandFrame = NpcSet.GetPlayerStandFrame(TRUE);
- m_WalkFrame = NpcSet.GetPlayerWalkFrame(TRUE);
- m_RunFrame = NpcSet.GetPlayerRunFrame(TRUE);
- }
- else
- {
- strcpy(szNpcTypeName, "女主角");
- m_StandFrame = NpcSet.GetPlayerStandFrame(FALSE);
- m_WalkFrame = NpcSet.GetPlayerWalkFrame(FALSE);
- m_RunFrame = NpcSet.GetPlayerRunFrame(FALSE);
- }
- #endif
- // TODO: Load Player Data;
- m_WalkSpeed = NpcSet.GetPlayerWalkSpeed();
- m_RunSpeed = NpcSet.GetPlayerRunSpeed();
- m_AttackFrame = NpcSet.GetPlayerAttackFrame();
- m_HurtFrame = NpcSet.GetPlayerHurtFrame();
- }
- else
- {
- GetNpcCopyFromTemplate(nNpcSettingIdx, nLevel);
- #ifndef _SERVER
- g_NpcSetting.GetString(nNpcSettingIdx + 2, "NpcResType", "", szNpcTypeName, sizeof(szNpcTypeName));
- if (!szNpcTypeName[0])
- {
- g_NpcKindFile.GetString(2, "人物名称", "", szNpcTypeName, sizeof(szNpcTypeName));//如果没找到,用第一个npc代替
- }
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIMode", 12, &m_AiMode);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam1", 12, &m_AiParam[0]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam2", 12, &m_AiParam[1]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam3", 12, &m_AiParam[2]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam4", 12, &m_AiParam[3]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam5", 12, &m_AiParam[4]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam6", 12, &m_AiParam[5]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "AIParam7", 12, &m_AiParam[6]);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "ActiveRadius", 12, &m_ActiveRadius);
- g_NpcSetting.GetInteger(nNpcSettingIdx + 2, "ClientOnly", 0, &m_bClientOnly);
- // 飞行类,11,12,17,用AiParam[6]保存策划设定高度
- // add by flying
- if (m_AiMode == 11 || m_AiMode == 12 || m_AiMode == 17)
- m_AiParam[6] = m_AiMode;
- #endif
- }
- #ifndef _SERVER
- m_DataRes.Init(szNpcTypeName, &g_NpcResList);
- m_DataRes.SetAction(m_ClientDoing);
- m_DataRes.SetRideHorse(m_bRideHorse);
- m_DataRes.SetArmor(m_ArmorType);
- m_DataRes.SetHelm(m_HelmType);
- m_DataRes.SetHorse(m_HorseType);
- m_DataRes.SetWeapon(m_WeaponType);
- #endif
- m_CurrentCamp = m_Camp;
- }
- void KNpc::GetMpsPos(int *pPosX, int *pPosY)
- {
- #ifdef _SERVER
- SubWorld[m_SubWorldIndex].Map2Mps(m_RegionIndex, m_MapX, m_MapY, m_OffX, m_OffY, pPosX, pPosY);
- #else
- SubWorld[m_SubWorldIndex].Map2Mps(m_RegionIndex, m_MapX, m_MapY, m_OffX, m_OffY, pPosX, pPosY);
- // KSubWorld::Map2Mps(C_REGION_X(m_RegionIndex), C_REGION_Y(m_RegionIndex), m_MapX, m_MapY, m_OffX, m_OffY, pPosX, pPosY);
- #endif
- }
- BOOL KNpc::SetActiveSkill(int nSkillIdx)
- {
- if (nSkillIdx <= 0 || nSkillIdx >= MAX_NPCSKILL)
- return FALSE;
- if (!(m_SkillList.m_Skills[nSkillIdx].SkillId && m_SkillList.m_Skills[nSkillIdx].CurrentSkillLevel))
- return FALSE;
- m_ActiveSkillID = m_SkillList.m_Skills[nSkillIdx].SkillId;
- int nLevel = m_SkillList.m_Skills[nSkillIdx].SkillLevel;
- _ASSERT(m_ActiveSkillID < MAX_SKILL && nLevel < MAX_SKILLLEVEL && nLevel > 0);
-
- ISkill * pISkill = g_SkillManager.GetSkill(m_ActiveSkillID, nLevel);
- if (pISkill)
- {
- m_CurrentAttackRadius = pISkill->GetAttackRadius();
- }
- return TRUE;
- }
- void KNpc::SetAuraSkill(int nSkillID)
- {
- int nCurLevel = 0;
- if (nSkillID <= 0 || nSkillID >= MAX_SKILL)
- {
- nSkillID = 0;
- }
- else
- {
- nCurLevel = m_SkillList.GetCurrentLevel(nSkillID);
- if (nCurLevel <= 0)
- {
- nSkillID = 0;
- }
- else
- {
- _ASSERT(nSkillID < MAX_SKILL && nCurLevel < MAX_SKILLLEVEL);
-
- KSkill * pOrdinSkill = (KSkill *)g_SkillManager.GetSkill(nSkillID, nCurLevel);
- if (!pOrdinSkill || !pOrdinSkill->IsAura())
- {
- nSkillID = 0;
- }
- }
- }
- m_ActiveAuraID = nSkillID;
- #ifdef _SERVER
- if (m_ActiveAuraID)
- {
- int nStateSpecialId = 0;
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nSkillID, nCurLevel);
-
- if (pOrdinSkill)
- {
- nStateSpecialId = pOrdinSkill->GetStateSpecailId();
- }
-
- if (nStateSpecialId) m_btStateInfo[m_nNextStatePos] = nStateSpecialId;
- if ((++m_nNextStatePos) >= MAX_NPC_RECORDER_STATE) m_nNextStatePos = 0;
- BroadCastState();
- }
- else
- {
- UpdateNpcStateInfo();
- BroadCastState();
- }
- #endif
- #ifndef _SERVER
- SKILL_CHANGEAURASKILL_COMMAND ChangeAuraMsg;
- ChangeAuraMsg.ProtocolType = c2s_changeauraskill;
- ChangeAuraMsg.m_nAuraSkill = m_ActiveAuraID;
- if (g_pClient)
- g_pClient->SendPackToServer(&ChangeAuraMsg, sizeof(SKILL_CHANGEAURASKILL_COMMAND));
- #endif
- }
- BOOL KNpc::SetPlayerIdx(int nIdx)
- {
- if (nIdx <= 0 || nIdx >= MAX_PLAYER)
- return FALSE;
- if (m_Kind != kind_player)
- return FALSE;
- m_nPlayerIdx = nIdx;
- return TRUE;
- }
- #ifdef _SERVER
- BOOL KNpc::SendSyncData(int nClient)
- {
- BOOL bRet = FALSE;
- NPC_SYNC NpcSync;
- NpcSync.ProtocolType = (BYTE)s2c_syncnpc;
- NpcSync.m_btKind = (BYTE)m_Kind;
- NpcSync.Camp = (BYTE)m_Camp;
- NpcSync.CurrentCamp = (BYTE)m_CurrentCamp;
- NpcSync.m_bySeries = (BYTE)m_Series;
- NpcSync.m_Doing = (BYTE)m_Doing;
- if (m_CurrentLifeMax > 0)
- NpcSync.LifePerCent = (BYTE)((m_CurrentLife << 7) / m_CurrentLifeMax);//Question只改了这部分,其它的也需要spe修改
- else
- NpcSync.LifePerCent = 0;
- if (this->IsPlayer())
- NpcSync.m_btMenuState = (BYTE)Player[this->m_nPlayerIdx].m_cMenuState.m_nState;
- else
- NpcSync.m_btMenuState = 0;
- GetMpsPos((int *)&NpcSync.MapX, (int *)&NpcSync.MapY);
- NpcSync.ID = m_dwID;
- NpcSync.NpcSettingIdx = MAKELONG(m_Level, m_NpcSettingIdx);
- // NpcSync.NpcEnchant = (WORD)m_NpcEnchant;
- NpcSync.NpcEnchant = (WORD)this->m_cGold.GetGoldType();
- strcpy(NpcSync.m_szName, Name);
- NpcSync.m_wLength = sizeof(NPC_SYNC) - 1 - sizeof(NpcSync.m_szName) + strlen(NpcSync.m_szName);
- if (SUCCEEDED(g_pServer->PackDataToClient(nClient, (BYTE*)&NpcSync, NpcSync.m_wLength + 1)))
- {
- //printf("Packing sync data ok...n");
- bRet = TRUE;
- }
- else
- {
- printf("Packing sync data failed...n");
- return FALSE;
- }
- g_DebugLog("[Sync]%d:%s<%d> request to %d. size:%d", SubWorld[m_SubWorldIndex].m_dwCurrentTime, Name, m_Kind, nClient, NpcSync.m_wLength + 1);
- if (IsPlayer())
- {
- PLAYER_SYNC PlayerSync;
- PlayerSync.ProtocolType = (BYTE)s2c_syncplayer;
- PlayerSync.ID = m_dwID;
- PlayerSync.ArmorType = (BYTE)m_ArmorType;
- PlayerSync.AttackSpeed = (BYTE)m_CurrentAttackSpeed;
- PlayerSync.CastSpeed = (BYTE)m_CurrentCastSpeed;
- PlayerSync.HelmType = (BYTE)m_HelmType;
- PlayerSync.HorseType = (BYTE)m_HorseType;
- PlayerSync.RunSpeed = (BYTE)m_CurrentRunSpeed;
- PlayerSync.WalkSpeed = (BYTE)m_CurrentWalkSpeed;
- PlayerSync.WeaponType = (BYTE)m_WeaponType;
- PlayerSync.RankID = (BYTE)m_btRankId;
- PlayerSync.m_btSomeFlag = 0;
- if (Player[m_nPlayerIdx].m_cPK.GetNormalPKState())
- PlayerSync.m_btSomeFlag |= 0x01;
- if (Npc[Player[m_nPlayerIdx].m_nIndex].m_FightMode)
- PlayerSync.m_btSomeFlag |= 0x02;
- if (Player[m_nPlayerIdx].m_bSleepMode)
- PlayerSync.m_btSomeFlag |= 0x04;
- if (SUCCEEDED(g_pServer->PackDataToClient(nClient, (BYTE*)&PlayerSync, sizeof(PLAYER_SYNC))))
- {
- //printf("Packing player sync data ok...n");
- bRet = TRUE;
- }
- else
- {
- printf("Packing player sync data failed...n");
- return FALSE;
- }
- }
- return bRet;
- }
- // 平时数据的同步
- void KNpc::NormalSync()
- {
- if (m_Doing == do_revive || m_Doing == do_death || !m_Index || m_RegionIndex < 0)
- return;
- NPC_NORMAL_SYNC NpcSync;
- int nMpsX, nMpsY;
- GetMpsPos(&nMpsX, &nMpsY);
- NpcSync.ProtocolType = (BYTE)s2c_syncnpcmin;
- NpcSync.ID = m_dwID;
- if (m_CurrentLife > 0)
- NpcSync.LifePerCent = (BYTE)((m_CurrentLife << 7) / m_CurrentLifeMax);
- else
- NpcSync.LifePerCent = 0;
- NpcSync.MapX = nMpsX;
- NpcSync.MapY = nMpsY;
- NpcSync.Camp = (BYTE)m_CurrentCamp;
- NpcSync.State = 0;
- if (m_FreezeState.nTime > 0)
- NpcSync.State |= STATE_FREEZE;
- if (m_PoisonState.nTime > 0)
- NpcSync.State |= STATE_POISON;
- if (m_ConfuseState.nTime > 0)
- NpcSync.State |= STATE_CONFUSE;
- if (m_StunState.nTime > 0)
- NpcSync.State |= STATE_STUN;
- NpcSync.Doing = (BYTE)m_Doing;
- // 由于同步数据每次同步的很少,所以上限就是MAX_PLAYER
- POINT POff[8] =
- {
- {0, 32},
- {-16, 32},
- {-16, 0},
- {-16, -32},
- {0, -32},
- {16, -32},
- {16, 0},
- {16, 32},
- };
- int nMaxCount = MAX_PLAYER;//MAX_BROADCAST_COUNT;
- CURREGION.BroadCast(&NpcSync, sizeof(NPC_NORMAL_SYNC), nMaxCount, m_MapX, m_MapY);
- int j;
- for (j = 0; j < 8; j++)
- {
- int nConRegion = CURREGION.m_nConnectRegion[j];
- if (nConRegion == -1)
- continue;
- _ASSERT(m_SubWorldIndex >= 0 && nConRegion >= 0);
- SubWorld[m_SubWorldIndex].m_Region[nConRegion].BroadCast((BYTE*)&NpcSync, sizeof(NPC_NORMAL_SYNC), nMaxCount, m_MapX - POff[j].x, m_MapY - POff[j].y);
- }
- if (IsPlayer())
- {
- PLAYER_NORMAL_SYNC PlayerSync;
- PlayerSync.ProtocolType = (BYTE)s2c_syncplayermin;
- PlayerSync.ID = m_dwID;
- PlayerSync.AttackSpeed = (BYTE)m_CurrentAttackSpeed;
- PlayerSync.CastSpeed = (BYTE)m_CurrentCastSpeed;
- PlayerSync.RunSpeed = (BYTE)m_CurrentRunSpeed;
- PlayerSync.WalkSpeed = (BYTE)m_CurrentWalkSpeed;
- PlayerSync.HelmType = (BYTE)m_HelmType;
- PlayerSync.ArmorType = (BYTE)m_ArmorType;
- PlayerSync.WeaponType = (BYTE)m_WeaponType;
- PlayerSync.HorseType = (BYTE)m_HorseType;
- PlayerSync.RankID = (BYTE)m_btRankId;
- PlayerSync.m_btSomeFlag = 0;
- if (Player[m_nPlayerIdx].m_cPK.GetNormalPKState())
- PlayerSync.m_btSomeFlag |= 0x01;
- if (m_FightMode)
- PlayerSync.m_btSomeFlag |= 0x02;
- if (Player[m_nPlayerIdx].m_bSleepMode)
- PlayerSync.m_btSomeFlag |= 0x04;
- if (Player[m_nPlayerIdx].m_cTong.GetOpenFlag())
- PlayerSync.m_btSomeFlag |= 0x08;
- int nMaxCount = MAX_PLAYER;//MAX_BROADCAST_COUNT;
- CURREGION.BroadCast(&PlayerSync, sizeof(PLAYER_NORMAL_SYNC), nMaxCount, m_MapX, m_MapY);
- for (j = 0; j < 8; j++)
- {
- int nConRegion = CURREGION.m_nConnectRegion[j];
- if (nConRegion == -1)
- continue;
- SubWorld[m_SubWorldIndex].m_Region[nConRegion].BroadCast((BYTE*)&PlayerSync, sizeof(PLAYER_NORMAL_SYNC), nMaxCount, m_MapX - POff[j].x, m_MapY - POff[j].y);
- }
- NPC_PLAYER_TYPE_NORMAL_SYNC sSync;
- sSync.ProtocolType = s2c_syncnpcminplayer;
- sSync.m_dwNpcID = m_dwID;
- if (m_CurrentLife > 0 && m_CurrentLifeMax > 0)
- sSync.m_btLifePerCent = (BYTE)((m_CurrentLife << 7) / m_CurrentLifeMax);
- else
- sSync.m_btLifePerCent = 0;
- // sSync.m_nRegionID = SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].m_RegionID;
- sSync.m_btCamp = (BYTE)m_CurrentCamp;
- sSync.m_dwMapX = nMpsX;
- sSync.m_dwMapY = nMpsY;
- sSync.m_wOffX = m_OffX;
- sSync.m_wOffY = m_OffY;
- sSync.m_byDoing = this->m_Doing;
- g_pServer->PackDataToClient(Player[m_nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(sSync));
- }
- }
- void KNpc::BroadCastRevive(int nType)
- {
- if (!IsPlayer())
- return;
- if (m_RegionIndex < 0)
- return;
- NPC_REVIVE_SYNC NpcReviveSync;
- NpcReviveSync.ProtocolType = s2c_playerrevive;
- NpcReviveSync.ID = m_dwID;
- NpcReviveSync.Type = (BYTE)nType;
- POINT POff[8] =
- {
- {0, 32},
- {-16, 32},
- {-16, 0},
- {-16, -32},
- {0, -32},
- {16, -32},
- {16, 0},
- {16, 32},
- };
- int nMaxCount = MAX_BROADCAST_COUNT;
- CURREGION.BroadCast((BYTE*)&NpcReviveSync, sizeof(NPC_REVIVE_SYNC), nMaxCount, m_MapX, m_MapY);
- int j;
- for (j = 0; j < 8; j++)
- {
- int nConRegion = CURREGION.m_nConnectRegion[j];
- if (nConRegion == -1)
- continue;
- SubWorld[m_SubWorldIndex].m_Region[nConRegion].BroadCast((BYTE*)&NpcReviveSync, sizeof(NPC_REVIVE_SYNC), nMaxCount, m_MapX - POff[j].x, m_MapY - POff[j].y);
- }
- }
- int KNpc::GetPlayerIdx()
- {
- if (m_Kind != kind_player)
- return 0;
- return m_nPlayerIdx;
- }
- #endif
- #ifndef _SERVER
- #include "scene/KScenePlaceC.h"
- int KNpc::PaintInfo(int nHeightOffset, bool bSelect, int nFontSize, DWORD dwBorderColor)
- {
- int nMpsX, nMpsY;
- GetMpsPos(&nMpsX, &nMpsY);
- DWORD dwColor;
- int nHeightOff = nHeightOffset + nFontSize + 1;
-
- if (m_Kind == kind_player)
- {
- switch(m_CurrentCamp)
- {
- case camp_begin:
- dwColor = 0xffffffff;
- break;
- case camp_justice:
- dwColor = 0xff000000 | (255 << 16) | (168 << 8) | 94;
- break;
- case camp_evil:
- dwColor = 0xff000000 | (255 << 16) | (146 << 8) | 255;
- break;
- case camp_balance:
- dwColor = 0xff000000 | (85 << 16) | (255 << 8) | 145;
- break;
- case camp_free:
- dwColor = 0xff000000 | (255 << 16);
- break;
- default:
- dwColor = 0xffff00ff;
- break;
- /* case camp_animal:
- dwColor =
- break;
- case camp_event:
- break;*/
- }
-
- char szString[128];
- strcpy(szString, Name);
- if (m_FreezeState.nTime || m_PoisonState.nTime || m_ConfuseState.nTime || m_StunState.nTime)
- {
- strcat(szString, "(");
- if (m_FreezeState.nTime)
- strcat(szString, "冰");
- if (m_PoisonState.nTime)
- strcat(szString, "毒");
- if (m_ConfuseState.nTime)
- strcat(szString, "乱");
- if (m_StunState.nTime)
- strcat(szString, "晕");
- strcat(szString, ")");
- }
- g_pRepresent->OutputText(nFontSize, szString, KRF_ZERO_END, nMpsX - nFontSize * g_StrLen(Name) / 4, nMpsY, dwColor, 0, nHeightOff, dwBorderColor);
- nHeightOffset += nFontSize + 1;
- }
- else if (m_Kind == kind_dialoger)
- {
- dwColor = 0xffffffff;
- g_pRepresent->OutputText(nFontSize, Name, KRF_ZERO_END, nMpsX - nFontSize * g_StrLen(Name) / 4, nMpsY, dwColor, 0, nHeightOff, dwBorderColor);
- nHeightOffset += nFontSize + 1;
- }
- else if (bSelect)
- {
- if (this->m_cGold.GetGoldType() == 0)
- dwColor = 0xffffffff;
- else
- dwColor = 0xffebb200; // 金色
- g_pRepresent->OutputText(nFontSize, Name, KRF_ZERO_END, nMpsX - nFontSize * g_StrLen(Name) / 4, nMpsY, dwColor, 0, nHeightOff, dwBorderColor);
- nHeightOffset += nFontSize + 1;
- }
-
- #ifdef SWORDONLINE_SHOW_DBUG_INFO
- if (Player[CLIENT_PLAYER_INDEX].m_DebugMode)
- {
- char szNameID[50];
- sprintf(szNameID,"[%d]", m_dwID);
- g_pRepresent->OutputText(12, szNameID, KRF_ZERO_END, nMpsX, nMpsY + 20, 0xfff0fff0, 0, m_Height);
- }
-
- if (Player[CLIENT_PLAYER_INDEX].m_nIndex == m_Index && Player[CLIENT_PLAYER_INDEX].m_DebugMode)
- {
- char szMsg[256];
- int nCount[9];
- for (int i = 0; i < 9; i++)
- nCount[i] = 0;
- if (LEFTUPREGIONIDX >= 0)
- nCount[0] = LEFTUPREGION.m_NpcList.GetNodeCount();
- if (UPREGIONIDX >= 0)
- nCount[1] = UPREGION.m_NpcList.GetNodeCount();
- if (RIGHTUPREGIONIDX >= 0)
- nCount[2] = RIGHTUPREGION.m_NpcList.GetNodeCount();
- if (LEFTREGIONIDX >= 0)
- nCount[3] = LEFTREGION.m_NpcList.GetNodeCount();
- if (m_RegionIndex >= 0)
- nCount[4] = CURREGION.m_NpcList.GetNodeCount();
- if (RIGHTREGIONIDX >= 0)
- nCount[5] = RIGHTREGION.m_NpcList.GetNodeCount();
- if (LEFTDOWNREGIONIDX >= 0)
- nCount[6] = LEFTDOWNREGION.m_NpcList.GetNodeCount();
- if (DOWNREGIONIDX >= 0)
- nCount[7] = DOWNREGION.m_NpcList.GetNodeCount();
- if (RIGHTDOWNREGIONIDX >= 0)
- nCount[8] = RIGHTDOWNREGION.m_NpcList.GetNodeCount();
-
- int nPosX, nPosY;
- GetMpsPos(&nPosX, &nPosY);
- sprintf(szMsg,
- "NpcID:%d Life:%dnRegionIndex:%d Pos:%d,%dnPlayerNumber:%dn"
- "NpcNumber:n%02d,%02d,%02dn%02d,%02d,%02dn%02d,%02d,%02d",
- m_dwID,
- m_CurrentLife,
- m_RegionIndex,
- m_MapX,
- m_MapY,
- CURREGION.m_PlayerList.GetNodeCount(),
- nCount[0], nCount[1], nCount[2],
- nCount[3], nCount[4], nCount[5],
- nCount[6], nCount[7], nCount[8]
- );
-
- g_pRepresent->OutputText(12, szMsg, -1, 320, 40, 0xffffffff);
- }
- #endif
- return nHeightOffset;
- }
- int KNpc::PaintChat(int nHeightOffset)
- {
- if (m_Kind != kind_player)
- return nHeightOffset;
- if (m_nChatContentLen <= 0)
- return nHeightOffset;
- if (m_nChatNumLine <= 0)
- return nHeightOffset;
- int nFontSize = 12;
- int nWidth, nHeight;
- int nMpsX, nMpsY;
- KRUShadow sShadow;
- KOutputTextParam sParam;
- sParam.BorderColor = 0;
- sParam.nNumLine = m_nChatNumLine;
- nWidth = m_nChatFontWidth * nFontSize / 2;
- nHeight = sParam.nNumLine * (nFontSize + 1);
- nWidth += 6; //为了好看
- nHeight += 5; //为了好看
- GetMpsPos(&nMpsX, &nMpsY);
- sParam.nX = nMpsX - nWidth / 2;
- sParam.nY = nMpsY;
- sParam.nZ = nHeightOffset + nHeight;
- sParam.Color = SHOW_CHAT_COLOR;
- sParam.nSkipLine = 0;
- sParam.nVertAlign = 0;
- sShadow.oPosition.nX = sParam.nX;
- sShadow.oPosition.nX -= 3; //为了好看
- sShadow.oPosition.nY = sParam.nY;
- sShadow.oPosition.nZ = sParam.nZ;
- sShadow.oEndPos.nX = sParam.nX + nWidth;
- sShadow.oEndPos.nX += 2; //为了好看
- sShadow.oEndPos.nY = sParam.nY;
- sShadow.oEndPos.nZ = sParam.nZ - nHeight;
- //sShadow.Color.Color_dw = 0x00FFFF00;
- //g_pRepresent->DrawPrimitives(1, &sShadow, RU_T_RECT, false);
- sShadow.Color.Color_dw = 0x14000000;
- //g_pRepresent->DrawPrimitives(1, &sShadow, RU_T_SHADOW, false);
-
- sParam.bPicPackInSingleLine = true;
- g_pRepresent->OutputRichText(nFontSize, &sParam, m_szChatBuffer, m_nChatContentLen, nWidth);
- return sParam.nZ;
- }
- #include "../../Engine/Src/Text.h"
- int KNpc::SetChatInfo(const char* Name, const char* pMsgBuff, unsigned short nMsgLength)
- {
- int nFontSize = 12;
- char szChatBuffer[MAX_SENTENCE_LENGTH];
- memset(szChatBuffer, 0, sizeof(szChatBuffer));
- if (nMsgLength)
- {
- int nOffset = 0;
- if (pMsgBuff[0] != KTC_TAB)
- {
- szChatBuffer[nOffset] = (char)KTC_COLOR;
- nOffset++;
- szChatBuffer[nOffset] = (char)0xFF;
- nOffset++;
- szChatBuffer[nOffset] = (char)0xFF;
- nOffset++;
- szChatBuffer[nOffset] = (char)0x00;
- nOffset++;
- strncpy(szChatBuffer + nOffset, Name, 32);
- nOffset += strlen(Name);
- szChatBuffer[nOffset] = ':';
- nOffset++;
- szChatBuffer[nOffset] = (char)KTC_COLOR_RESTORE;
- nOffset++;
- }
- else
- {
- pMsgBuff ++;
- nMsgLength --;
- }
- if (nMsgLength)
- {
- memcpy(szChatBuffer + nOffset, pMsgBuff, nMsgLength);
- nOffset += nMsgLength;
- memset(m_szChatBuffer, 0, sizeof(m_szChatBuffer));
- m_nChatContentLen = MAX_SENTENCE_LENGTH;
- TGetLimitLenEncodedString(szChatBuffer, nOffset, nFontSize, SHOW_CHAT_WIDTH,
- m_szChatBuffer, m_nChatContentLen, 2, true);
- m_nChatNumLine = TGetEncodedTextLineCount(m_szChatBuffer, m_nChatContentLen, SHOW_CHAT_WIDTH, m_nChatFontWidth, nFontSize, 0, 0, true);
- if (m_nChatNumLine >= 2)
- m_nChatNumLine = 2;
- m_nCurChatTime = IR_GetCurrentTime();
- return true;
- }
- }
- return false;
- }
- int KNpc::PaintLife(int nHeightOffset, bool bSelect)
- {
- if (!bSelect &&
- (m_Kind != kind_player &&
- m_Kind != kind_partner)
- )
- return nHeightOffset;
- if (m_CurrentLifeMax <= 0)
- return nHeightOffset;
- if (relation_enemy == NpcSet.GetRelation(m_Index, Player[CLIENT_PLAYER_INDEX].m_nIndex) &&
- (m_Kind == kind_player ||
- m_Kind == kind_partner)
- )
- return nHeightOffset; //有敌对关系的玩家不显示生命
- int nMpsX, nMpsY;
- GetMpsPos(&nMpsX, &nMpsY);
- int nWid = SHOW_LIFE_WIDTH;
- int nHei = SHOW_LIFE_HEIGHT;
- KRUShadow Blood;
- int nX = m_CurrentLife * 100 / m_CurrentLifeMax;
- if (nX >= 50)
- {
- Blood.Color.Color_b.r = 0;
- Blood.Color.Color_b.g = 255;
- Blood.Color.Color_b.b = 0;
- }
- else if (nX >= 25)
- {
- Blood.Color.Color_b.r = 255;
- Blood.Color.Color_b.g = 255;
- Blood.Color.Color_b.b = 0;
- }
- else
- {
- Blood.Color.Color_b.r = 255;
- Blood.Color.Color_b.g = 0;
- Blood.Color.Color_b.b = 0;
- }
- Blood.Color.Color_b.a = 0;
- Blood.oPosition.nX = nMpsX - nWid / 2;
- Blood.oPosition.nY = nMpsY;
- Blood.oPosition.nZ = nHeightOffset + nHei;
- Blood.oEndPos.nX = Blood.oPosition.nX + nWid * nX / 100;
- Blood.oEndPos.nY = nMpsY;
- Blood.oEndPos.nZ = nHeightOffset;
- g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, FALSE);
- Blood.Color.Color_b.r = 128;
- Blood.Color.Color_b.g = 128;
- Blood.Color.Color_b.b = 128;
- Blood.oPosition.nX = Blood.oEndPos.nX;
- Blood.oEndPos.nX = nMpsX + nWid / 2;
- g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, FALSE);
-
- return nHeightOffset + nHei;
- }
- int KNpc::PaintMana(int nHeightOffset)
- {
- if (m_Kind != kind_player &&
- m_Kind != kind_partner)
- return nHeightOffset;
- if (m_CurrentManaMax <= 0)
- return nHeightOffset;
- return nHeightOffset;
- int nMpsX, nMpsY;
- GetMpsPos(&nMpsX, &nMpsY);
- int nWid = 38;
- int nHei = 5;
- KRUShadow Blood;
- int nX = m_CurrentMana * 100 / m_CurrentManaMax;
- if (nX >= 50)
- {
- Blood.Color.Color_b.r = 0;
- Blood.Color.Color_b.g = 0;
- Blood.Color.Color_b.b = 255;
- }
- else if (nX >= 25)
- {
- Blood.Color.Color_b.r = 255;
- Blood.Color.Color_b.g = 255;
- Blood.Color.Color_b.b = 0;
- }
- else
- {
- Blood.Color.Color_b.r = 255;
- Blood.Color.Color_b.g = 0;
- Blood.Color.Color_b.b = 0;
- }
- Blood.Color.Color_b.a = 0;
- Blood.oPosition.nX = nMpsX - nWid / 2;
- Blood.oPosition.nY = nMpsY;
- Blood.oPosition.nZ = nHeightOffset + nHei;
- Blood.oEndPos.nX = Blood.oPosition.nX + nWid * nX / 100;
- Blood.oEndPos.nY = nMpsY;
- Blood.oEndPos.nZ = nHeightOffset;
- g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, FALSE);
- Blood.Color.Color_b.r = 255;
- Blood.Color.Color_b.g = 255;
- Blood.Color.Color_b.b = 255;
- Blood.oPosition.nX = Blood.oEndPos.nX;
- Blood.oEndPos.nX = nMpsX + nWid / 2;
- g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, FALSE);
-
- return nHeightOffset + nHei;
- }
- void KNpc::Paint()
- {
- if (m_ResDir != m_Dir)
- {
- int nDirOff = m_Dir - m_ResDir;
- if (nDirOff > 32)
- nDirOff -= 64;
- else if (nDirOff < - 32)
- nDirOff += 64;
- m_ResDir += nDirOff / 2;
- if (m_ResDir >= 64)
- m_ResDir -= 64;
- if (m_ResDir < 0)
- m_ResDir += 64;
- }
- m_DataRes.Draw(m_Index, m_ResDir, m_Frames.nTotalFrame, m_Frames.nCurrentFrame);
- int nHeight = GetNpcPate() + GetNpcPatePeopleInfo();
- DrawMenuState(nHeight);
- }
- #endif
- //--------------------------------------------------------------------------
- // 功能:增加基本最大生命点
- //--------------------------------------------------------------------------
- void KNpc::AddBaseLifeMax(int nLife)
- {
- m_LifeMax += nLife;
- m_CurrentLifeMax = m_LifeMax;
- }
- //--------------------------------------------------------------------------
- // 功能:增加当前最大生命点
- //--------------------------------------------------------------------------
- void KNpc::AddCurLifeMax(int nLife)
- {
- m_CurrentLifeMax += nLife;
- }
- //--------------------------------------------------------------------------
- // 功能:增加基本最大体力点
- //--------------------------------------------------------------------------
- void KNpc::AddBaseStaminaMax(int nStamina)
- {
- m_StaminaMax += nStamina;
- m_CurrentStaminaMax = m_StaminaMax;
- }
- //--------------------------------------------------------------------------
- // 功能:增加当前最大体力点
- //--------------------------------------------------------------------------
- void KNpc::AddCurStaminaMax(int nStamina)
- {
- m_CurrentStaminaMax += nStamina;
- }
- //--------------------------------------------------------------------------
- // 功能:增加基本最大内力点
- //--------------------------------------------------------------------------
- void KNpc::AddBaseManaMax(int nMana)
- {
- m_ManaMax += nMana;
- m_CurrentManaMax = m_ManaMax;
- }
- //--------------------------------------------------------------------------
- // 功能:增加当前最大内力点
- //--------------------------------------------------------------------------
- void KNpc::AddCurManaMax(int nMana)
- {
- m_CurrentManaMax += nMana;
- }
- /*
- //--------------------------------------------------------------------------
- // 功能:重新计算生命回复速度
- //--------------------------------------------------------------------------
- void KNpc::ResetLifeReplenish()
- {
- m_LifeReplenish = (m_Level + 5) / 6;
- m_CurrentLifeReplenish = m_LifeReplenish;
- }
- */
- /*
- //--------------------------------------------------------------------------
- // 功能:计算当前最大生命点
- //--------------------------------------------------------------------------
- void KNpc::CalcCurLifeMax()
- {
- }
- */
- /*
- //--------------------------------------------------------------------------
- // 功能:计算当前最大体力点
- //--------------------------------------------------------------------------
- void KNpc::CalcCurStaminaMax()
- {
- m_CurrentStaminaMax = m_StaminaMax; // 还需要加上 装备、技能、药物(临时)等的影响
- }
- */
- /*
- //--------------------------------------------------------------------------
- // 功能:计算当前最大内力点
- //--------------------------------------------------------------------------
- void KNpc::CalcCurManaMax()
- {
- m_CurrentManaMax = m_ManaMax; // 还需要加上 装备、技能、药物(临时)等的影响
- }
- */
- //--------------------------------------------------------------------------
- // 功能:计算当前生命回复速度
- //--------------------------------------------------------------------------
- void KNpc::CalcCurLifeReplenish()
- {
- m_CurrentLifeReplenish = m_LifeReplenish; // 与角色系别、角色等级和是否使用药剂、技能和魔法装备有关
- }
- void KNpc::Remove()
- {
- /* m_LoopFrames = 0;
- m_Index = 0;
- m_PlayerIdx = -1;
- m_Kind = 0;
- m_dwID = 0;
- Name[0] = 0;*/
- Init();
- #ifndef _SERVER
- m_DataRes.Remove(m_Index);
- #endif
- }
- #ifndef _SERVER
- void KNpc::RemoveRes()
- {
- m_DataRes.Remove(m_Index);
- }
- #endif
- //--------------------------------------------------------------------------
- // 功能:设定此 npc 的五行属性(内容还没完成)not end
- //--------------------------------------------------------------------------
- void KNpc::SetSeries(int nSeries)
- {
- if (nSeries >= series_metal && nSeries < series_num)
- m_Series = nSeries;
- else
- m_Series = series_metal;
- }
- /*!*****************************************************************************
- // Function : KNpc::SetStateSkill
- // Purpose :
- // Return : void
- // Argumant : int nSkillID
- // Argumant : int nLevel
- // Argumant : void *pData
- // Argumant : int nDataNum
- // Argumant : int nTime -1表示被动技能,时间无限
- // Comments :
- // Author : Spe
- *****************************************************************************/
- void KNpc::SetStateSkillEffect(int nLauncher, int nSkillID, int nLevel, void *pData, int nDataNum, int nTime/* = -1*/)
- {
- if (nLevel <= 0|| nSkillID <= 0) return ;
- _ASSERT(nDataNum < MAX_SKILL_STATE);
- if (nDataNum >= MAX_SKILL_STATE)
- nDataNum = MAX_SKILL_STATE;
-
- #ifdef _SERVER
- if (IsPlayer() && pData && nDataNum >= 0)
- {
- STATE_EFFECT_SYNC Sync;
- Sync.ProtocolType = s2c_syncstateeffect;
- Sync.m_dwSkillID = nSkillID;
- Sync.m_nLevel = nLevel;
- Sync.m_nTime = nTime;
- memcpy(Sync.m_MagicAttrib, pData, sizeof(KMagicAttrib) * nDataNum);
- Sync.m_wLength = sizeof(Sync) - sizeof(KMagicAttrib) * (MAX_SKILL_STATE - nDataNum) - 1;
- g_pServer->PackDataToClient(Player[m_nPlayerIdx].m_nNetConnectIdx, &Sync, Sync.m_wLength + 1);
- }
- #endif
- KStateNode* pNode;
- KMagicAttrib* pTemp = NULL;
- pNode = (KStateNode *)m_StateSkillList.GetHead();
- while(pNode)
- {
- if (pNode->m_SkillID == nSkillID)
- {
- if (pNode->m_Level == nLevel)
- {
- pNode->m_LeftTime = nTime;
- }
- else if (pNode->m_Level < nLevel)
- {
- pTemp = (KMagicAttrib *)pData;
- for (int i = 0; i < nDataNum; i++)
- {
- // 清除原技能的影响
- ModifyAttrib(nLauncher, &pNode->m_State[i]);
- // 把新等级下技能的影响计算到NPC身上
- ModifyAttrib(nLauncher, pTemp);
- pNode->m_State[i].nValue[0] = -pTemp->nValue[0];
- pNode->m_State[i].nValue[1] = -pTemp->nValue[1];
- pNode->m_State[i].nValue[2] = -pTemp->nValue[2];
- pTemp++;
- }
- }
- return;
- }
- pNode = (KStateNode *)pNode->GetNext();
- }
- // 没有在循环中返回,说明是新技能
- pNode = new KStateNode;
- pNode->m_SkillID = nSkillID;
- pNode->m_Level = nLevel;
- pNode->m_LeftTime = nTime;
- _ASSERT(nSkillID < MAX_SKILL && nLevel < MAX_SKILLLEVEL);
-
- KSkill * pOrdinSkill = (KSkill *)g_SkillManager.GetSkill(nSkillID, nLevel);
- if (pOrdinSkill)
- pNode->m_StateGraphics = pOrdinSkill->GetStateSpecailId();
- else
- pNode->m_StateGraphics = 0;
- #ifdef _SERVER
- //如果为新的状态则需要更新角色的状态信息,并且广播给各个玩家
- if (pNode->m_StateGraphics)
- {
- m_btStateInfo[m_nNextStatePos] = pNode->m_StateGraphics;
- if ((++m_nNextStatePos) >= MAX_NPC_RECORDER_STATE) m_nNextStatePos = 0;
- BroadCastState();
- }
- #else
- if (IsPlayer() && pNode->m_StateGraphics)
- {
- m_btStateInfo[m_nNextStatePos] = pNode->m_StateGraphics;
- if ((++m_nNextStatePos) >= MAX_NPC_RECORDER_STATE)
- m_nNextStatePos = 0;
- }
- #endif
- pTemp = (KMagicAttrib *)pData;
- for (int i = 0; i < nDataNum; i++)
- {
- // 调整NPC属性
- ModifyAttrib(nLauncher, pTemp);
- // 把相反值加入链表中以供移除时使用
- pNode->m_State[i].nAttribType = pTemp->nAttribType;
- pNode->m_State[i].nValue[0] = -pTemp->nValue[0];
- pNode->m_State[i].nValue[1] = -pTemp->nValue[1];
- pNode->m_State[i].nValue[2] = -pTemp->nValue[2];
- pTemp++;
- }
- m_StateSkillList.AddTail(pNode);
- }
- /*!*****************************************************************************
- // Function : KNpc::ModifyMissleCollsion
- // Purpose :
- // Return : BOOL
- // Argumant : BOOL bCollsion
- // Comments :
- // Author : Spe
- *****************************************************************************/
- BOOL KNpc::ModifyMissleCollsion(BOOL bCollsion)
- {
- if (bCollsion)
- return TRUE;
- if (g_RandPercent(m_CurrentPiercePercent))
- return TRUE;
- else
- return FALSE;
- }
- int KNpc::ModifyMissleLifeTime(int nLifeTime)
- {
- if (IsPlayer())
- {
- //return Player[m_PlayerIdx].GetWeapon().GetRange();
- return nLifeTime;
- }
- else
- {
- return nLifeTime;
- }
- }
- int KNpc::ModifyMissleSpeed(int nSpeed)
- {
- if (m_CurrentSlowMissle)
- {
- return nSpeed / 2;
- }
- return nSpeed;
- }
- BOOL KNpc::DoManyAttack()
- {
- m_ProcessAI = 0;
-
- KSkill * pSkill =(KSkill*) GetActiveSkill();
- if (!pSkill)
- return FALSE;
-
- if (pSkill->GetChildSkillNum() <= m_SpecialSkillStep)
- goto ExitManyAttack;
- #ifndef _SERVER
- m_DataRes.SetBlur(TRUE);
- #endif
-
- m_Frames.nTotalFrame = pSkill->GetMissleGenerateTime(m_SpecialSkillStep);
-
- int x, y;
- SubWorld[m_SubWorldIndex].Map2Mps(m_RegionIndex, m_MapX, m_MapY, m_OffX, m_OffY, &x, &y);
- // m_DesX = x;
- // m_DesY = y;
-
- #ifndef _SERVER
- if (m_nPlayerIdx > 0)
- pSkill->PlayPreCastSound(m_nSex, x ,y);
- if (g_Random(2))
- m_ClientDoing = cdo_attack;
- else
- m_ClientDoing = cdo_attack1;
- #endif
-
- m_Doing = do_manyattack;
-
- m_Frames.nCurrentFrame = 0;
- return TRUE;
- ExitManyAttack:
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- return TRUE;
- }
- void KNpc::OnManyAttack()
- {
- if (WaitForFrame())
- {
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- KSkill * pSkill = (KSkill*)GetActiveSkill();
- if (!pSkill)
- return ;
- int nPhySkillId = pSkill->GetChildSkillId();//GetCurActiveWeaponSkill(); Changed
- if (nPhySkillId > 0)
- {
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nPhySkillId, pSkill->m_ulLevel, SKILL_SS_Missles);
- if (pOrdinSkill)
- {
- pOrdinSkill->Cast(m_Index, m_SkillParam1, m_SkillParam2);
- }
- }
- m_SpecialSkillStep ++;
- DoManyAttack();
- }
- }
- BOOL KNpc::DoRunAttack()
- {
- m_ProcessAI = 0;
- switch(m_SpecialSkillStep)
- {
- case 0:
- m_Frames.nTotalFrame = m_RunSpeed;
- m_ProcessAI = 0;
-
- #ifndef _SERVER
- m_DataRes.SetBlur(TRUE);
- if (m_FightMode)
- {
- m_ClientDoing = cdo_fightrun;
- }
- else
- {
- m_ClientDoing = cdo_run;
- }
- #endif
-
- if (m_DesX < 0 && m_DesY > 0)
- {
- int x, y;
- SubWorld[m_SubWorldIndex].Map2Mps
- (
- Npc[m_DesY].m_RegionIndex,
- Npc[m_DesY].m_MapX,
- Npc[m_DesY].m_MapY,
- Npc[m_DesY].m_OffX,
- Npc[m_DesY].m_OffY,
- &x,
- &y
- );
- m_DesX = x;
- m_DesY = y;
- }
- m_Frames.nCurrentFrame = 0;
- m_Doing = do_runattack;
- break;
- case 1:
- #ifndef _SERVER
- if (g_Random(2))
- m_ClientDoing = cdo_attack;
- else
- m_ClientDoing = cdo_attack1;
- int x, y, tx, ty;
- SubWorld[m_SubWorldIndex].Map2Mps(m_RegionIndex, m_MapX, m_MapY, m_OffX, m_OffY, &x, &y);
- if (m_SkillParam1 == -1)
- {
- Npc[m_SkillParam2].GetMpsPos(&tx, &ty);
- }
- else
- {
- tx = m_SkillParam1;
- ty = m_SkillParam2;
- }
- m_Dir = g_GetDirIndex(x, y, tx, ty);
- #endif
- m_Frames.nTotalFrame = m_AttackFrame * 100 / (100 + m_CurrentAttackSpeed);
- m_Frames.nCurrentFrame = 0;
- m_Doing = do_runattack;
- break;
- case 2:
- case 3:
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- return FALSE;
- break;
- }
- m_Frames.nCurrentFrame = 0;
-
- return TRUE;
- }
- void KNpc::OnRunAttack()
- {
-
- if (m_SpecialSkillStep == 0)
- {
- OnRun();
- KSkill * pSkill = (KSkill*)GetActiveSkill();
- if (!pSkill)
- return ;
-
- if (m_Doing == do_stand || (DWORD)m_nCurrentMeleeTime > pSkill->GetMissleGenerateTime(0))
- {
- m_SpecialSkillStep ++;
- m_nCurrentMeleeTime = 0;
- DoRunAttack();
-
- }
- else
- m_nCurrentMeleeTime ++;
- m_ProcessAI = 0;
- }
- else if (m_SpecialSkillStep == 1)
- {
- if (WaitForFrame() &&m_Frames.nTotalFrame != 0)
- {
- DoStand();
- m_ProcessAI = 1;
- }
- else if (IsReachFrame(ATTACKACTION_EFFECT_PERCENT))
- {
- KSkill * pSkill = (KSkill*)GetActiveSkill();
- if (!pSkill)
- return ;
-
- int nCurPhySkillId = pSkill->GetChildSkillId();//GetCurActiveWeaponSkill();
- if (nCurPhySkillId > 0)
- {
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nCurPhySkillId, pSkill->m_ulLevel, SKILL_SS_Missles);
- if (pOrdinSkill)
- {
- pOrdinSkill->Cast(m_Index, m_SkillParam1, m_SkillParam2);
- }
- }
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- }
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- }
- else
- {
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- }
- }
- BOOL KNpc::DoJumpAttack()
- {
- m_ProcessAI = 0;
-
- switch(m_SpecialSkillStep)
- {
- case 0:
- DoJump();
- #ifndef _SERVER
- m_DataRes.SetBlur(TRUE);
- m_ClientDoing = cdo_jump;
- #endif
- m_Doing = do_jumpattack;
- break;
-
- case 1:
- #ifndef _SERVER
- if (g_Random(2))
- m_ClientDoing = cdo_attack;
- else
- m_ClientDoing = cdo_attack1;
- int x, y, tx, ty;
- SubWorld[m_SubWorldIndex].Map2Mps(m_RegionIndex, m_MapX, m_MapY, m_OffX, m_OffY, &x, &y);
- if (m_SkillParam1 == -1)
- {
- Npc[m_SkillParam2].GetMpsPos(&tx, &ty);
- }
- else
- {
- tx = m_SkillParam1;
- ty = m_SkillParam2;
- }
- m_Dir = g_GetDirIndex(x, y, tx, ty);
- #endif
- m_Frames.nTotalFrame = m_AttackFrame * 100 / (100 + m_CurrentAttackSpeed);
- m_Frames.nCurrentFrame = 0;
- m_Doing = do_jumpattack;
- break;
-
- case 2:
- case 3:
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- return FALSE;
- break;
- }
-
- m_Frames.nCurrentFrame = 0;
-
- return TRUE;
-
- }
- BOOL KNpc::OnJumpAttack()
- {
- if (m_SpecialSkillStep == 0)
- {
- if (!OnJump())
- {
- m_SpecialSkillStep ++;
- m_nCurrentMeleeTime = 0;
- DoJumpAttack();
- }
- m_ProcessAI = 0;
- }
- else if (m_SpecialSkillStep == 1)
- {
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- if (WaitForFrame() &&m_Frames.nTotalFrame != 0)
- {
- DoStand();
- m_ProcessAI = 1;
- }
- else if (IsReachFrame(ATTACKACTION_EFFECT_PERCENT))
- {
- KSkill * pSkill =(KSkill*) GetActiveSkill();
- if (!pSkill)
- return FALSE;
-
- int nCurPhySkillId = pSkill->GetChildSkillId();//GetCurActiveWeaponSkill();
- if (nCurPhySkillId > 0)
- {
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nCurPhySkillId, pSkill->m_ulLevel, SKILL_SS_Missles);
- if (pOrdinSkill)
- {
- pOrdinSkill->Cast(m_Index, m_SkillParam1, m_SkillParam2);
- }
- }
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- }
- }
- else
- {
- #ifndef _SERVER
- m_DataRes.SetBlur(FALSE);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_SpecialSkillStep = 0;
- return FALSE;
- }
- return TRUE;
- }
- BOOL KNpc::CheckHitTarget(int nAR, int nDf, int nIngore/* = 0*/)
- {
- int nDefense = nDf * (100 - nIngore) / 100;
- int nPercent = 0;
- //Question nAr+ nDefense == 0 ,error!so.....,must modify
- if ((nAR + nDefense) == 0)
- nPercent = 50;
- else
- nPercent = nAR * 100 / (nAR + nDefense);
- if (nPercent > MAX_HIT_PERCENT)
- nPercent = MAX_HIT_PERCENT;
- if (nPercent < MIN_HIT_PERCENT)
- nPercent = MIN_HIT_PERCENT;
- BOOL bRet = g_RandPercent(nPercent);
- g_DebugLog("[数值]AttackRating %d : Defense %d: RandomPercent (%d, %d)", nAR, nDf, nPercent, bRet);
- return bRet;
- }
- void KNpc::GetNpcCopyFromTemplate(int nNpcTemplateId, int nLevel)
- {
- if (nNpcTemplateId < 0 || nLevel < 1 )
- return ;
-
- if (g_pNpcTemplate[nNpcTemplateId][nLevel]) //数据有效则拷贝,否则重新生成
- LoadDataFromTemplate(nNpcTemplateId, nLevel);
- else
- {
- if (!g_pNpcTemplate[nNpcTemplateId][0])
- {
- g_pNpcTemplate[nNpcTemplateId][0] = new KNpcTemplate;
- g_pNpcTemplate[nNpcTemplateId][0]->InitNpcBaseData(nNpcTemplateId);
- g_pNpcTemplate[nNpcTemplateId][0]->m_NpcSettingIdx = nNpcTemplateId;
- g_pNpcTemplate[nNpcTemplateId][0]->m_bHaveLoadedFromTemplate = TRUE;
- }
- KLuaScript * pLevelScript = NULL;
- #ifdef _SERVER
- pLevelScript = (KLuaScript*)g_GetScript(
- g_pNpcTemplate[nNpcTemplateId][0]->m_dwLevelSettingScript
- );
-
- if (pLevelScript == NULL)
- pLevelScript = g_pNpcLevelScript;
- #else
- KLuaScript LevelScript;
- if (!g_pNpcTemplate[nNpcTemplateId][0]->m_szLevelSettingScript[0])
- pLevelScript = g_pNpcLevelScript;
- else
- {
- LevelScript.Init();
- if (!LevelScript.Load(g_pNpcTemplate[nNpcTemplateId][0]->m_szLevelSettingScript))
- {
- g_DebugLog ("[error]致命错误,无法正确读取%s", g_pNpcTemplate[nNpcTemplateId][0]->m_szLevelSettingScript);
- _ASSERT(0);
- pLevelScript = g_pNpcLevelScript;
- }
- else
- pLevelScript = &LevelScript;
- }
- #endif
- g_pNpcTemplate[nNpcTemplateId][nLevel] = new KNpcTemplate;
- *g_pNpcTemplate[nNpcTemplateId][nLevel] = *g_pNpcTemplate[nNpcTemplateId][0];
- g_pNpcTemplate[nNpcTemplateId][nLevel]->m_nLevel = nLevel;
- g_pNpcTemplate[nNpcTemplateId][nLevel]->InitNpcLevelData(&g_NpcKindFile, nNpcTemplateId, pLevelScript, nLevel);
- g_pNpcTemplate[nNpcTemplateId][nLevel]->m_bHaveLoadedFromTemplate = TRUE;
- LoadDataFromTemplate(nNpcTemplateId,nLevel);
- }
- }
- void KNpc::LoadDataFromTemplate(int nNpcTemplateId, int nLevel)
- {
- if (nNpcTemplateId < 0 )
- {
- g_DebugLog("载入Npc%d模板请求非法!", nNpcTemplateId);
- return ;
- }
-
- KNpcTemplate * pNpcTemp = g_pNpcTemplate[nNpcTemplateId][nLevel];
- strcpy(Name,pNpcTemp->Name);
- m_Kind = pNpcTemp->m_Kind;
- m_Camp = pNpcTemp->m_Camp;
- m_Series = pNpcTemp->m_Series;
- m_HeadImage = pNpcTemp->m_HeadImage;
- m_bClientOnly = pNpcTemp->m_bClientOnly;
- m_CorpseSettingIdx = pNpcTemp->m_CorpseSettingIdx;
- m_DeathFrame = pNpcTemp->m_DeathFrame;
- m_WalkFrame = pNpcTemp->m_WalkFrame;
- m_RunFrame = pNpcTemp->m_RunFrame;
- m_HurtFrame = pNpcTemp->m_HurtFrame;
- m_WalkSpeed = pNpcTemp->m_WalkSpeed;
- m_AttackFrame = pNpcTemp->m_AttackFrame;
- m_CastFrame = pNpcTemp->m_CastFrame;
- m_RunSpeed = pNpcTemp->m_RunSpeed;
- m_StandFrame = pNpcTemp->m_StandFrame;
- m_StandFrame1 = pNpcTemp->m_StandFrame1;
- m_NpcSettingIdx = pNpcTemp->m_NpcSettingIdx;
- m_nStature = pNpcTemp->m_nStature;
- #ifdef _SERVER
- m_Treasure = pNpcTemp->m_Treasure;
- m_SkillList = pNpcTemp->m_SkillList;
- m_AiMode = pNpcTemp->m_AiMode;
- m_AiAddLifeTime = 0;
- m_pDropRate = pNpcTemp->m_pItemDropRate;
- if (!m_AiSkillRadiusLoadFlag)
- {
- m_AiSkillRadiusLoadFlag = 1;
- int i;
- for (i = 0; i < MAX_AI_PARAM - 1; i ++)
- m_AiParam[i] = pNpcTemp->m_AiParam[i];
- int nMaxRadius = 0, nTempRadius;
- KSkill *pSkill;
- for (i = 1; i < MAX_NPC_USE_SKILL + 1; i++)
- {
- pSkill = (KSkill*)g_SkillManager.GetSkill(m_SkillList.m_Skills[i].SkillId, m_SkillList.m_Skills[i].SkillLevel);
- if (!pSkill)
- continue;
- nTempRadius = pSkill->GetAttackRadius();
- if (nTempRadius > nMaxRadius)
- nMaxRadius = nTempRadius;
- }
- m_AiParam[MAX_AI_PARAM - 1] = nMaxRadius * nMaxRadius;
- }
- m_FireResistMax = pNpcTemp->m_FireResistMax;
- m_ColdResistMax = pNpcTemp->m_ColdResistMax;
- m_LightResistMax = pNpcTemp->m_LightResistMax;
- m_PoisonResistMax = pNpcTemp->m_PoisonResistMax;
- m_PhysicsResistMax = pNpcTemp->m_PhysicsResistMax;
- m_ActiveRadius = pNpcTemp->m_ActiveRadius;
- m_VisionRadius = pNpcTemp->m_VisionRadius;
- m_AIMAXTime = pNpcTemp->m_AIMAXTime;
- m_HitRecover = pNpcTemp->m_HitRecover;
- m_ReviveFrame = pNpcTemp->m_ReviveFrame;
- m_Experience = pNpcTemp->m_Experience;
- m_CurrentExperience = m_Experience;
- m_LifeMax = pNpcTemp->m_LifeMax;
- m_LifeReplenish = pNpcTemp->m_LifeReplenish;
- m_AttackRating = pNpcTemp->m_AttackRating;
- m_Defend = pNpcTemp->m_Defend;
- m_PhysicsDamage = pNpcTemp->m_PhysicsDamage;
- m_RedLum = pNpcTemp->m_RedLum;
- m_GreenLum = pNpcTemp->m_GreenLum;
- m_BlueLum = pNpcTemp->m_BlueLum;
- m_FireResist = pNpcTemp->m_FireResist;
- m_ColdResist = pNpcTemp->m_ColdResist;
- m_LightResist = pNpcTemp->m_LightResist;
- m_PoisonResist = pNpcTemp->m_PoisonResist;
- m_PhysicsResist = pNpcTemp->m_PhysicsResist;
- #else
- m_LifeMax = pNpcTemp->m_LifeMax;
- m_ArmorType = pNpcTemp->m_ArmorType;
- m_HelmType = pNpcTemp->m_HelmType;
- m_WeaponType = pNpcTemp->m_WeaponType;
- m_HorseType = pNpcTemp->m_HorseType;
- m_bRideHorse = pNpcTemp->m_bRideHorse;
- strcpy(ActionScript, pNpcTemp->ActionScript);
- #endif
-
- /*for (int j = 0; j < 4; j ++)
- m_SkillList.Add()
- int m_nSkillID[4];
- int m_nSkillLevel[4];*/
- //BOOL m_bHaveLoadedFromTemplate;
- //int m_nNpcTemplateId;
- m_Level = pNpcTemp->m_nLevel;
- RestoreNpcBaseInfo();
-
- }
- //-----------------------------------------------------------------------
- // 功能:设定物理攻击的最大最小值 not end 需要考虑调用的地方
- //-----------------------------------------------------------------------
- void KNpc::SetPhysicsDamage(int nMinDamage, int nMaxDamage)
- {
- m_PhysicsDamage.nValue[0] = nMinDamage;
- m_PhysicsDamage.nValue[2] = nMaxDamage;
- }
- //-----------------------------------------------------------------------
- // 功能:设定攻击命中率
- //-----------------------------------------------------------------------
- void KNpc::SetBaseAttackRating(int nAttackRating)
- {
- m_AttackRating = nAttackRating;
- // 此处还需要加上装备、技能的影响,计算出当前值
- m_CurrentAttackRating = m_AttackRating;
- }
- //-----------------------------------------------------------------------
- // 功能:设定防御力
- //-----------------------------------------------------------------------
- void KNpc::SetBaseDefence(int nDefence)
- {
- m_Defend = nDefence;
- // 此处还需要加上装备、技能的影响,计算出当前值
- m_CurrentDefend = m_Defend;
- }
- /*
- //-----------------------------------------------------------------------
- // 功能:设定行走速度
- //-----------------------------------------------------------------------
- void KNpc::SetBaseWalkSpeed(int nSpeed)
- {
- m_WalkSpeed = nSpeed;
- // 此处还需要加上装备、技能的影响,计算出当前值 (not end)
- m_CurrentWalkSpeed = m_WalkSpeed;
- }
- */
- /*
- //-----------------------------------------------------------------------
- // 功能:设定跑步速度
- //-----------------------------------------------------------------------
- void KNpc::SetBaseRunSpeed(int nSpeed)
- {
- m_RunSpeed = nSpeed;
- // 此处还需要加上装备、技能的影响,计算出当前值 (not end)
- m_CurrentRunSpeed = m_RunSpeed;
- }
- */
- #ifdef _SERVER
- void KNpc::DeathPunish(int nMode, int nBelongPlayer)
- {
- #define LOSE_EXP_SCALE 10
- if (IsPlayer())
- {
- // 被npc kill
- if (nMode == enumDEATH_MODE_NPC_KILL)
- {
- // 经验减少
- if (Player[m_nPlayerIdx].m_nExp > 0)
- {
- int nSubExp;
- if (m_Level <= 10)
- nSubExp = (PlayerSet.m_cLevelAdd.GetLevelExp(m_Level) * 2) / 100;
- else
- nSubExp = (PlayerSet.m_cLevelAdd.GetLevelExp(m_Level) * 4) / 100;
- if (Player[m_nPlayerIdx].m_nExp >= nSubExp)
- Player[m_nPlayerIdx].DirectAddExp( -nSubExp );
- else
- Player[m_nPlayerIdx].DirectAddExp( -Player[m_nPlayerIdx].m_nExp );
- }
- // 钱减少
- int nMoney = Player[m_nPlayerIdx].m_ItemList.GetEquipmentMoney() / 2;
- if (nMoney > 0)
- {
- Player[m_nPlayerIdx].m_ItemList.CostMoney(nMoney);
- // 损失金钱消息
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_DEC_MONEY;
- sMsg.m_lpBuf = (void *)(nMoney);
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- g_pServer->PackDataToClient(Player[m_nPlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
- if (nMoney / 2 > 0)
- PlayerDeadCreateMoneyObj(nMoney / 2);
- }
- }
- // 切磋,没有惩罚
- else if (nMode == enumDEATH_MODE_PLAYER_NO_PUNISH)
- {
- return;
- }
- else if (nMode == enumDEATH_MODE_PKBATTLE_PUNISH)
- {
- return;
- }
- // PK致死,按PK值计算惩罚
- else //if (nMode == enumDEATH_MODE_PLAYER_PUNISH)
- {
- int nPKValue;
- nPKValue = Player[this->m_nPlayerIdx].m_cPK.GetPKValue();
- if (nPKValue < 0)
- nPKValue = 0;
- if (nPKValue > MAX_DEATH_PUNISH_PK_VALUE)
- nPKValue = MAX_DEATH_PUNISH_PK_VALUE;
- // 经验减少
- int nLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(m_Level);
- Player[m_nPlayerIdx].DirectAddExp( -(nLevelExp * PlayerSet.m_sPKPunishParam[nPKValue].m_nExp / 100) );
- // 钱减少
- int nMoney = Player[m_nPlayerIdx].m_ItemList.GetEquipmentMoney() * PlayerSet.m_sPKPunishParam[nPKValue].m_nMoney / 100;
- if (nMoney > 0)
- {
- Player[m_nPlayerIdx].m_ItemList.CostMoney(nMoney);
- // 损失金钱消息
- SHOW_MSG_SYNC sMsg;
- sMsg.ProtocolType = s2c_msgshow;
- sMsg.m_wMsgID = enumMSG_ID_DEC_MONEY;
- sMsg.m_lpBuf = (void *)(nMoney);
- sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
- g_pServer->PackDataToClient(Player[m_nPlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
- sMsg.m_lpBuf = 0;
-
- if (nMoney / 2 > 0)
- PlayerDeadCreateMoneyObj(nMoney / 2);
- }
- // 丢失物品
- Player[m_nPlayerIdx].m_ItemList.AutoLoseItemFromEquipmentRoom(PlayerSet.m_sPKPunishParam[nPKValue].m_nItem);
- // 丢失穿在身上的装备
- if (g_Random(100) < PlayerSet.m_sPKPunishParam[nPKValue].m_nEquip)
- {
- Player[m_nPlayerIdx].m_ItemList.AutoLoseEquip();
- }
- Player[m_nPlayerIdx].m_cPK.AddPKValue(NpcSet.m_nBeKilledAddPKValue);
- if (m_nLastDamageIdx)
- {
- if (Npc[m_nLastDamageIdx].IsPlayer())
- {
- KPlayerChat::MakeEnemy(Name, Npc[m_nLastDamageIdx].Name);
- }
- }
- }
- }
- // else if (m_nLastDamageIdx && Npc[m_nLastDamageIdx].IsPlayer())
- else if (nBelongPlayer > 0 && m_pDropRate)
- {
- for (int i = 0; i < m_CurrentTreasure; i++)
- {
- if (g_RandPercent(m_pDropRate->nMoneyRate))
- {
- LoseMoney(nBelongPlayer);
- }
- else
- {
- LoseSingleItem(nBelongPlayer);
- }
- }
- }
- }
- // 玩家死的时候掉出来的钱生成一个object
- void KNpc::PlayerDeadCreateMoneyObj(int nMoneyNum)
- {
- int nX, nY;
- POINT ptLocal;
- KMapPos Pos;
- GetMpsPos(&nX, &nY);
- ptLocal.x = nX;
- ptLocal.y = nY;
- SubWorld[m_SubWorldIndex].GetFreeObjPos(ptLocal);
- Pos.nSubWorld = m_SubWorldIndex;
- SubWorld[m_SubWorldIndex].Mps2Map(ptLocal.x, ptLocal.y,
- &Pos.nRegion, &Pos.nMapX, &Pos.nMapY,
- &Pos.nOffX, &Pos.nOffY);
-
- int nObjIdx = ObjSet.AddMoneyObj(Pos, nMoneyNum);
- if (nObjIdx > 0 && nObjIdx < MAX_OBJECT)
- {
- Object[nObjIdx].SetItemBelong(-1);
- }
- }
- void KNpc::LoseMoney(int nBelongPlayer)
- {
- int nX, nY;
- POINT ptLocal;
- KMapPos Pos;
- int nMoney = m_CurrentExperience * m_pDropRate->nMoneyScale / 100;
- if (nMoney <= 0)
- return;
- GetMpsPos(&nX, &nY);
- ptLocal.x = nX;
- ptLocal.y = nY;
- SubWorld[m_SubWorldIndex].GetFreeObjPos(ptLocal);
-
- Pos.nSubWorld = m_SubWorldIndex;
- SubWorld[m_SubWorldIndex].Mps2Map(ptLocal.x, ptLocal.y,
- &Pos.nRegion, &Pos.nMapX, &Pos.nMapY,
- &Pos.nOffX, &Pos.nOffY);
-
- int nObjIdx = ObjSet.AddMoneyObj(Pos, nMoney);
- if (nObjIdx > 0 && nObjIdx < MAX_OBJECT)
- {
- if (nBelongPlayer > 0)
- Object[nObjIdx].SetItemBelong(nBelongPlayer);
- else
- Object[nObjIdx].SetItemBelong(-1);
- }
- }
- void KNpc::LoseSingleItem(int nBelongPlayer)
- {
- if (!m_pDropRate)
- return;
- if (m_pDropRate->nMaxItemLevelScale <= 0 || m_pDropRate->nMinItemLevelScale <= 0)
- return;
- int nRand = g_Random(m_pDropRate->nMaxRandRate);
- int nCheckRand = 0; // 累加概率,确认是否落在区间内
- int i;
- for (i = 0; i < m_pDropRate->nCount; i++)
- {
- if (nRand >= nCheckRand && nRand < nCheckRand + m_pDropRate->pItemParam[i].nRate)
- {
- break;
- }
- nCheckRand += m_pDropRate->pItemParam[i].nRate;
- }
- if (i == m_pDropRate->nCount)
- return;
- int nGenre, nSeries, nLuck, nDetail, nParticular, nLevel, pnMagicLevel[6];
- nGenre = m_pDropRate->pItemParam[i].nGenre;
- nDetail = m_pDropRate->pItemParam[i].nDetailType;
- nParticular = m_pDropRate->pItemParam[i].nParticulType;
- nSeries = m_Series;
- nLuck = Player[nBelongPlayer].m_nCurLucky;
- int nMaxLevel = m_Level / m_pDropRate->nMaxItemLevelScale;
- int nMinLevel = m_Level / m_pDropRate->nMinItemLevelScale;
- if (nMaxLevel > m_pDropRate->nMaxItemLevel)
- nMaxLevel = m_pDropRate->nMaxItemLevel;
- if (nMinLevel < m_pDropRate->nMinItemLevel)
- nMinLevel = m_pDropRate->nMinItemLevel;
- if (nMaxLevel < nMinLevel)
- {
- int nTemp = nMinLevel;
- nMinLevel = nMaxLevel;
- nMaxLevel = nTemp;
- }
-
- nLevel = g_Random(nMaxLevel - nMinLevel) + nMinLevel;
- BOOL bSkip = FALSE;
- for (int j = 0; j < 6; j++)
- {
- if (!bSkip)
- {
- if (g_Random(m_pDropRate->nMagicRate))
- {
- pnMagicLevel[j] = nLevel;
- }
- else
- {
- pnMagicLevel[j] = 0;
- bSkip = TRUE;
- }
- }
- else
- {
- pnMagicLevel[j] = 0;
- }
- }
- int nIdx = ItemSet.Add(nGenre, nSeries, nLevel, nLuck, nDetail, nParticular, pnMagicLevel, g_SubWorldSet.GetGameVersion());
- if (nIdx <= 0)
- return;
- int nX, nY;
- POINT ptLocal;
- KMapPos Pos;
- GetMpsPos(&nX, &nY);
- ptLocal.x = nX;
- ptLocal.y = nY;
- SubWorld[m_SubWorldIndex].GetFreeObjPos(ptLocal);
-
- Pos.nSubWorld = m_SubWorldIndex;
- SubWorld[m_SubWorldIndex].Mps2Map(ptLocal.x, ptLocal.y,
- &Pos.nRegion, &Pos.nMapX, &Pos.nMapY,
- &Pos.nOffX, &Pos.nOffY);
- int nObj;
- KObjItemInfo sInfo;
- sInfo.m_nItemID = nIdx;
- sInfo.m_nItemWidth = Item[nIdx].GetWidth();
- sInfo.m_nItemHeight = Item[nIdx].GetHeight();
- sInfo.m_nMoneyNum = 0;
- strcpy(sInfo.m_szName, Item[nIdx].GetName());
- sInfo.m_nColorID = 0;
- sInfo.m_nMovieFlag = 1;
- sInfo.m_nSoundFlag = 1;
- nObj = ObjSet.Add(Item[nIdx].GetObjIdx(), Pos, sInfo);
- if (nObj == -1)
- {
- ItemSet.Remove(nIdx);
- }
- else
- {
- if (nBelongPlayer > 0)
- Object[nObj].SetItemBelong(nBelongPlayer);
- else
- Object[nObj].SetItemBelong(-1);
- }
- }
- void KNpc::Revive()
- {
- //RestoreLiveData();
- RestoreNpcBaseInfo();
- int nRegion, nMapX, nMapY, nOffX, nOffY;
- SubWorld[m_SubWorldIndex].Mps2Map(m_OriginX, m_OriginY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
- m_RegionIndex = nRegion;
- m_MapX = nMapX;
- m_MapY = nMapY;
- m_MapZ = 0;
- m_OffX = nOffX;
- m_OffY = nOffY;
- if (m_RegionIndex < 0)
- return;
- SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].AddRef(m_MapX, m_MapY, obj_npc);
- #ifdef _SERVER
- //SubWorld[m_SubWorldIndex].m_WorldMessage.Send(GWM_NPC_CHANGE_REGION, VOID_REGION, nRegion, m_Index);
- SubWorld[m_SubWorldIndex].NpcChangeRegion(VOID_REGION, nRegion, m_Index); // spe 03/06/28
- #else
- SubWorld[0].NpcChangeRegion(VOID_REGION, SubWorld[0].m_Region[nRegion].m_RegionID, m_Index);
- #endif
- DoStand();
- m_ProcessAI = 1;
- m_ProcessState = 1;
- m_AiAddLifeTime = 0;
- #ifdef _SERVER
- this->m_cGold.RandChangeGold();
- #endif
- }
- void KNpc::RestoreLiveData()
- {
- }
- #endif
- #ifdef _SERVER
- // 向周围九屏广播
- void KNpc::SendDataToNearRegion(void* pBuffer, DWORD dwSize)
- {
- _ASSERT(m_RegionIndex >= 0);
- if (m_RegionIndex < 0)
- return;
- POINT POff[8] =
- {
- {0, 32},
- {-16, 32},
- {-16, 0},
- {-16, -32},
- {0, -32},
- {16, -32},
- {16, 0},
- {16, 32},
- };
- int nMaxCount = MAX_BROADCAST_COUNT;
- SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].BroadCast(pBuffer, dwSize, nMaxCount, m_MapX, m_MapY);
- for (int i= 0; i < 8; i++)
- {
- if (SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].m_nConnectRegion[i] < 0)
- continue;
- SubWorld[m_SubWorldIndex].m_Region[SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].m_nConnectRegion[i]].BroadCast(pBuffer, dwSize, nMaxCount, m_MapX - POff[i].x, m_MapY - POff[i].y);
- }
- }
- #endif
- #ifdef _SERVER
- //-----------------------------------------------------------------------------
- // 功能:死亡时候计算PK值
- //-----------------------------------------------------------------------------
- int KNpc::DeathCalcPKValue(int nKiller)
- {
- // 出错
- if (nKiller <= 0 || nKiller >= MAX_NPC)
- return enumDEATH_MODE_NPC_KILL;
-
- if (m_nCurPKPunishState == enumDEATH_MODE_PKBATTLE_PUNISH)
- return enumDEATH_MODE_PKBATTLE_PUNISH;
- // 玩家之间,城镇内
- if (this->m_Kind != kind_player || Npc[nKiller].m_Kind != kind_player || !m_FightMode)
- return enumDEATH_MODE_NPC_KILL;
- // 如果是切磋,不计算
- if (Player[m_nPlayerIdx].m_cPK.GetExercisePKAim() == Npc[nKiller].m_nPlayerIdx)
- return enumDEATH_MODE_PLAYER_NO_PUNISH;
- // 如果是仇杀
- if (Player[m_nPlayerIdx].m_cPK.GetEnmityPKState() == enumPK_ENMITY_STATE_PKING &&
- Player[m_nPlayerIdx].m_cPK.GetEnmityPKAim() == Npc[nKiller].m_nPlayerIdx)
- {
- if (Player[Npc[nKiller].m_nPlayerIdx].m_cPK.IsEnmityPKLauncher())
- Player[Npc[nKiller].m_nPlayerIdx].m_cPK.AddPKValue(NpcSet.m_nEnmityAddPKValue);
- return enumDEATH_MODE_PLAYER_PUNISH;
- }
- // 如果等级差过大,算PK新手(HLv:LLv >= 3:2)
- if (m_Level <= 50 && Npc[nKiller].m_Level * 2 >= m_Level * 3)
- {
- if (!Player[m_nPlayerIdx].m_cPK.GetNormalPKState())
- {
- if (Npc[nKiller].m_CurrentCamp == camp_free)
- Player[Npc[nKiller].m_nPlayerIdx].m_cPK.AddPKValue(NpcSet.m_nKillerPKFactionAddPKValue);
- else
- Player[Npc[nKiller].m_nPlayerIdx].m_cPK.AddPKValue(NpcSet.m_nFactionPKFactionAddPKValue);
- }
- return enumDEATH_MODE_PLAYER_PUNISH;
- }
- return enumDEATH_MODE_PLAYER_PUNISH;
- }
- #endif
- #ifdef _SERVER
- //-----------------------------------------------------------------------------
- // 功能:查找周围9个Region中是否有指定的 player
- //-----------------------------------------------------------------------------
- BOOL KNpc::CheckPlayerAround(int nPlayerIdx)
- {
- if (nPlayerIdx <= 0 || m_RegionIndex < 0)
- return FALSE;
- if (SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].CheckPlayerIn(nPlayerIdx))
- return TRUE;
- int nRegionNo;
- for (int i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- if (SubWorld[m_SubWorldIndex].m_Region[nRegionNo].CheckPlayerIn(nPlayerIdx))
- return TRUE;
- }
- return FALSE;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定头顶状态
- //-------------------------------------------------------------------------
- void KNpc::SetMenuState(int nState, char *lpszSentence, int nLength)
- {
- this->m_DataRes.SetMenuState(nState, lpszSentence, nLength);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:获得头顶状态
- //-------------------------------------------------------------------------
- int KNpc::GetMenuState()
- {
- return this->m_DataRes.GetMenuState();
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:查找周围9个Region中是否有指定 ID 的 npc
- //-------------------------------------------------------------------------
- DWORD KNpc::SearchAroundID(DWORD dwID)
- {
- int nIdx, nRegionNo;
- nIdx = SubWorld[0].m_Region[m_RegionIndex].SearchNpc(dwID);
- if (nIdx)
- return nIdx;
- for (int i = 0; i < 8; i++)
- {
- nRegionNo = SubWorld[0].m_Region[m_RegionIndex].m_nConnectRegion[i];
- if ( nRegionNo < 0)
- continue;
- nIdx = SubWorld[0].m_Region[nRegionNo].SearchNpc(dwID);
- if (nIdx)
- return nIdx;
- }
- return 0;
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定特殊的只播放一遍的随身spr文件
- //-------------------------------------------------------------------------
- void KNpc::SetSpecialSpr(char *lpszSprName)
- {
- m_DataRes.SetSpecialSpr(lpszSprName);
- }
- #endif
- #ifndef _SERVER
- //-------------------------------------------------------------------------
- // 功能:设定瞬间特效
- //-------------------------------------------------------------------------
- void KNpc::SetInstantSpr(int nNo)
- {
- char szName[FILE_NAME_LENGTH];
- szName[0] = 0;
- NpcSet.m_cInstantSpecial.GetSprName(nNo, szName, sizeof(szName));
- if (szName[0])
- this->SetSpecialSpr(szName);
- }
- #endif
- #ifndef _SERVER
- int KNpc::GetNormalNpcStandDir(int nFrame)
- {
- return m_DataRes.GetNormalNpcStandDir(nFrame);
- }
- #endif
- #ifdef _SERVER
- //重新更新角色状态信息数据
- void KNpc::UpdateNpcStateInfo()
- {
- int i = 0;
- memset(m_btStateInfo, 0 ,sizeof(BYTE) * MAX_NPC_RECORDER_STATE);
- KStateNode *pNode = (KStateNode*)m_StateSkillList.GetTail();
- if (m_ActiveAuraID)
- {
- int nLevel = m_SkillList.GetCurrentLevel(m_ActiveAuraID);
- if (nLevel > 0)
- {
- int nSpecialID = 0;
- KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(m_ActiveAuraID, nLevel);
- if (pOrdinSkill)
- {
- if (nSpecialID = pOrdinSkill->GetStateSpecailId())
- m_btStateInfo[i++] = nSpecialID;
- }
- }
- }
- while ( pNode && i < MAX_NPC_RECORDER_STATE)
- {
- if (pNode->m_StateGraphics > 0)
- m_btStateInfo[i++] = pNode->m_StateGraphics;
- pNode = (KStateNode*)pNode->GetPrev();
- }
- }
- //广播状态数据
- void KNpc::BroadCastState()
- {
- if (m_RegionIndex < 0)
- return;
- NPC_SYNC_STATEINFO StateInfo;
- StateInfo.ProtocolType = (BYTE)s2c_syncnpcstate;
- StateInfo.m_ID = m_dwID;
- int i;
- for (i = 0; i < MAX_NPC_RECORDER_STATE; i++)
- StateInfo.m_btStateInfo[i] = m_btStateInfo[i];
- POINT POff[8] =
- {
- {0, 32},
- {-16, 32},
- {-16, 0},
- {-16, -32},
- {0, -32},
- {16, -32},
- {16, 0},
- {16, 32},
- };
- int nMaxCount = MAX_BROADCAST_COUNT;
- CURREGION.BroadCast(&StateInfo, sizeof(NPC_SYNC_STATEINFO), nMaxCount, m_MapX, m_MapY);
- for (i= 0; i < 8; i++)
- {
- if (CONREGIONIDX(i) == -1)
- continue;
- CONREGION(i).BroadCast(&StateInfo, sizeof(NPC_SYNC_STATEINFO), nMaxCount, m_MapX - POff[i].x, m_MapY - POff[i].y);
- }
- }
- #endif
- #ifndef _SERVER
- void KNpc::SetNpcState(BYTE* pNpcState)
- {
- ClearNpcState();
- if (!pNpcState)
- return ;
- for (int i = 0; i < MAX_NPC_RECORDER_STATE; i++)
- {
- if (*(pNpcState + i) != 0)
- {
- KStateNode * pNewNode = new KStateNode;
- pNewNode->m_StateGraphics = *(pNpcState + i);
- m_StateSkillList.AddTail(pNewNode);
- }
- }
- }
- #endif
- void KNpc::ClearNpcState()
- {
- KStateNode * pNode = (KStateNode*)m_StateSkillList.GetHead();
- KStateNode * pTempNode = NULL;
-
- while(pNode)
- {
- pTempNode = pNode;
- pNode = (KStateNode*) pNode->GetNext();
- pTempNode->Remove();
- delete pTempNode;
- }
- return;
- }
- void KNpc::RestoreNpcBaseInfo()
- {
- m_CurrentCamp = m_Camp;
- m_ActiveSkillID = 0;
- m_ActiveAuraID = 0;
- m_nPeopleIdx = 0;
- m_nLastDamageIdx = 0;
- m_nLastPoisonDamageIdx = 0;
- m_nObjectIdx = 0;
- m_CurrentLife = m_LifeMax;
- m_CurrentLifeMax = m_LifeMax;
- m_CurrentLifeReplenish = m_LifeReplenish;
- m_CurrentMana = m_ManaMax;
- m_CurrentManaMax = m_ManaMax;
- m_CurrentManaReplenish = m_ManaReplenish;
- m_CurrentStamina = m_StaminaMax;
- m_CurrentStaminaMax = m_StaminaMax;
- m_CurrentStaminaGain = m_StaminaGain;
- m_CurrentStaminaLoss = m_StaminaLoss;
- memset(&m_CurrentFireDamage, 0, sizeof(m_CurrentFireDamage));
- memset(&m_CurrentColdDamage, 0, sizeof(m_CurrentColdDamage));
- memset(&m_CurrentLightDamage, 0, sizeof(m_CurrentLightDamage));
- memset(&m_CurrentPoisonDamage, 0, sizeof(m_CurrentPoisonDamage));
- m_CurrentAttackRating = m_AttackRating;
- m_CurrentDefend = m_Defend;
- m_CurrentFireResist = m_FireResist;
- m_CurrentColdResist = m_ColdResist;
- m_CurrentPoisonResist = m_PoisonResist;
- m_CurrentLightResist = m_LightResist;
- m_CurrentPhysicsResist = m_PhysicsResist;
- m_CurrentFireResistMax = m_FireResistMax;
- m_CurrentColdResistMax = m_ColdResistMax;
- m_CurrentPoisonResistMax = m_PoisonResistMax;
- m_CurrentLightResistMax = m_LightResistMax;
- m_CurrentPhysicsResistMax = m_PhysicsResistMax;
- m_CurrentWalkSpeed = m_WalkSpeed;
- m_CurrentRunSpeed = m_RunSpeed;
- m_CurrentAttackSpeed = m_AttackSpeed;
- m_CurrentCastSpeed = m_CastSpeed;
- m_CurrentVisionRadius = m_VisionRadius;
- m_CurrentActiveRadius = m_ActiveRadius;
- m_CurrentHitRecover = m_HitRecover;
- m_CurrentTreasure = m_Treasure;
- m_CurrentDamage2Mana = 0;
- m_CurrentManaPerEnemy = 0;
- m_CurrentLifeStolen = 0;
- m_CurrentManaStolen = 0;
- m_CurrentStaminaStolen = 0;
- m_CurrentKnockBack = 0;
- m_CurrentDeadlyStrike = 0;
- m_CurrentBlindEnemy = 0;
- m_CurrentPiercePercent = 0;
- m_CurrentFreezeTimeReducePercent = 0;
- m_CurrentPoisonTimeReducePercent = 0;
- m_CurrentStunTimeReducePercent = 0;
- m_CurrentFireEnhance = 0;
- m_CurrentColdEnhance = 0;
- m_CurrentPoisonEnhance = 0;
- m_CurrentLightEnhance = 0;
- m_CurrentRangeEnhance = 0;
- m_CurrentHandEnhance = 0;
- ZeroMemory(m_CurrentMeleeEnhance, sizeof(m_CurrentMeleeEnhance));
- ClearStateSkillEffect();
- ClearNormalState();
- }
- #ifndef _SERVER
- void KNpc::DrawBorder()
- {
- if (m_Index <= 0)
- return;
- m_DataRes.DrawBorder();
- }
- int KNpc::DrawMenuState(int n)
- {
- if (m_Index <= 0)
- return n;
- return m_DataRes.DrawMenuState(n);
- }
- void KNpc::DrawBlood()
- {
- if (m_Kind != kind_normal)
- return;
- int nFontSize = 12;
- // KRUShadow Blood;
- //
- // char szString[128];
- // strcpy(szString, Name);
- // if (m_FreezeState.nTime || m_PoisonState.nTime || m_ConfuseState.nTime || m_StunState.nTime)
- // {
- // strcat(szString, "(");
- // if (m_FreezeState.nTime)
- // strcat(szString, "冰");
- // if (m_PoisonState.nTime)
- // strcat(szString, "毒");
- // if (m_ConfuseState.nTime)
- // strcat(szString, "乱");
- // if (m_StunState.nTime)
- // strcat(szString, "晕");
- // strcat(szString, ")");
- // }
- //
- // int nLength = g_StrLen(szString) * nFontSize / 2;
- // int nX = 400 - nLength / 2;
- // int nY = 28;
- // nLength += 40;
- //
- // Blood.Color.Color_b.r = 130;
- // Blood.Color.Color_b.g = 30;
- // Blood.Color.Color_b.b = 30;
- // Blood.Color.Color_b.a = 10;
- // Blood.oPosition.nX = nX - 20;
- // Blood.oPosition.nY = nY;
- // Blood.oPosition.nZ = 0;
- // Blood.oEndPos.nX = Blood.oPosition.nX + nLength * m_CurrentLife / m_CurrentLifeMax;
- // Blood.oEndPos.nY = nY + 16;
- //
- // g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, TRUE);
- //
- // Blood.Color.Color_b.r = 30;
- // Blood.oPosition.nX = Blood.oEndPos.nX;
- // Blood.oEndPos.nX = nX - 20 + nLength;
- //
- // g_pRepresent->DrawPrimitives(1, &Blood, RU_T_SHADOW, TRUE);
- //
- // g_pRepresent->OutputText(nFontSize, szString, KRF_ZERO_END, nX, nY + 2, 0xffffffff);
-
- int nHeightOff = GetNpcPate();
- //if (NpcSet.CheckShowLife())
- {
- nHeightOff = PaintLife(nHeightOff, true);
- nHeightOff += SHOW_SPACE_HEIGHT;
- }
- //if (NpcSet.CheckShowName())
- {
- nHeightOff = PaintInfo(nHeightOff, true);
- }
- }
- #endif
- #ifdef _SERVER
- int KNpc::SetPos(int nX, int nY)
- {
- if (m_SubWorldIndex < 0)
- {
- _ASSERT(0);
- return 0;
- }
- int nRegion, nMapX, nMapY, nOffX, nOffY;
- SubWorld[m_SubWorldIndex].Mps2Map(nX, nY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
- if (nRegion < 0)
- {
- g_DebugLog("[Script]SetPos error:SubWorld:%d, Pos(%d, %d)", SubWorld[m_SubWorldIndex].m_SubWorldID, nX, nY);
- return 0;
- }
- int nOldRegion = m_RegionIndex;
- if (m_RegionIndex >= 0)
- {
- SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- }
- m_RegionIndex = nRegion;
- m_MapX = nMapX;
- m_MapY = nMapY;
- m_MapZ = 0;
- m_OffX = nOffX;
- m_OffY = nOffY;
- if (nOldRegion != nRegion)
- {
- SubWorld[m_SubWorldIndex].NpcChangeRegion(nOldRegion, nRegion, m_Index);
- if (IsPlayer())
- SubWorld[m_SubWorldIndex].PlayerChangeRegion(nOldRegion, nRegion, m_nPlayerIdx);
- }
- SubWorld[m_SubWorldIndex].m_Region[nRegion].AddRef(m_MapX, m_MapY, obj_npc);
- DoStand();
- m_ProcessAI = 1;
- m_ProcessState = 1;
- return 1;
- }
- #endif
- #ifdef _SERVER
- int KNpc::ChangeWorld(DWORD dwSubWorldID, int nX, int nY)
- {
- int nTargetSubWorld = g_SubWorldSet.SearchWorld(dwSubWorldID);
- if (!IsPlayer())
- return 0;
-
-
- // 不在这台服务器上
- if (-1 == nTargetSubWorld)
- {
- if (m_SubWorldIndex >= 0)
- SubWorld[m_SubWorldIndex].m_MissionArray.RemovePlayer(m_nPlayerIdx);
- TobeExchangeServer(dwSubWorldID, nX, nY);
- g_DebugLog("[Map]World%d haven't been loaded!", dwSubWorldID);
- return 2; // 需要加切换服务器的处理 -- spe
- }
- Player[m_nPlayerIdx].m_nPrePayMoney = 0;// 不是跨服务器,不用还钱
- // 切换的世界就是本身
- if (nTargetSubWorld == m_SubWorldIndex)
- {
- // 只需切换座标
- return SetPos(nX, nY);
- }
-
- int nRegion, nMapX, nMapY, nOffX, nOffY;
- SubWorld[nTargetSubWorld].Mps2Map(nX, nY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
- // 切换到的坐标非法
- if (nRegion < 0)
- {
- g_DebugLog("[Map]Change Pos(%d,%d) Invalid!", nX, nY);
- return 0;
- }
-
- if (m_SubWorldIndex >= 0)
- SubWorld[m_SubWorldIndex].m_MissionArray.RemovePlayer(m_nPlayerIdx);
-
- // 真正开始切换工作
- if (m_SubWorldIndex >= 0 && m_RegionIndex >= 0)
- {
- SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].RemoveNpc(m_Index);// m_WorldMessage.Send(GWM_NPC_REMOVE, m_RegionIndex, m_Index);
- SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- }
- int nSourceSubWorld = m_SubWorldIndex;
- int nSourceRegion = m_RegionIndex;
- m_SubWorldIndex = nTargetSubWorld;
- m_RegionIndex = nRegion;
- m_MapX = nMapX;
- m_MapY = nMapY;
- m_MapZ = 0;
- m_OffX = nOffX;
- m_OffY = nOffY;
- SubWorld[nTargetSubWorld].m_Region[nRegion].AddNpc(m_Index);// m_WorldMessage.Send(GWM_NPC_ADD, nRegion, m_Index);
- SubWorld[nTargetSubWorld].m_Region[nRegion].AddRef(m_MapX, m_MapY, obj_npc);
- DoStand();
- m_ProcessAI = 1;
- if (IsPlayer())
- {
- SubWorld[nTargetSubWorld].SendSyncData(m_Index, Player[m_nPlayerIdx].m_nNetConnectIdx);
- SubWorld[nSourceSubWorld].RemovePlayer(nSourceRegion, m_nPlayerIdx);
- SubWorld[nTargetSubWorld].AddPlayer(nRegion, m_nPlayerIdx);
- }
- return 1;
- }
- #endif
- #ifdef _SERVER
- void KNpc::TobeExchangeServer(DWORD dwMapID, int nX, int nY)
- {
- if (!IsPlayer())
- {
- return;
- }
- m_OldFightMode = m_FightMode;
- m_bExchangeServer = TRUE;
- if (m_nPlayerIdx > 0 && m_nPlayerIdx <= MAX_PLAYER)
- {
- Player[m_nPlayerIdx].TobeExchangeServer(dwMapID, nX, nY);
- }
- }
- #endif
- BOOL KNpc::IsPlayer()
- {
- #ifdef _SERVER
- return m_Kind == kind_player;
- #else
- return m_Index == Player[CLIENT_PLAYER_INDEX].m_nIndex;
- #endif
- }
- // 清除NPC身上的非被动类的技能状态
- void KNpc::ClearStateSkillEffect()
- {
- KStateNode* pNode;
- pNode = (KStateNode *)m_StateSkillList.GetHead();
- while(pNode)
- {
- KStateNode* pTempNode = pNode;
- pNode = (KStateNode *)pNode->GetNext();
- if (pTempNode->m_LeftTime == -1) // 被动技能
- continue;
- if (pTempNode->m_LeftTime > 0)
- {
- for (int i = 0; i < MAX_SKILL_STATE; i++)
- {
- if (pTempNode->m_State[i].nAttribType)
- ModifyAttrib(m_Index, &pTempNode->m_State[i]);
- }
- _ASSERT(pTempNode != NULL);
- pTempNode->Remove();
- delete pTempNode;
- #ifdef _SERVER
- UpdateNpcStateInfo();
- BroadCastState();
- #endif
- pTempNode = NULL;
- continue;
- }
- }
- }
- void KNpc::ClearNormalState()
- {
- ZeroMemory(&m_PhysicsArmor, sizeof(m_PhysicsArmor));
- ZeroMemory(&m_ColdArmor, sizeof(m_ColdArmor));
- ZeroMemory(&m_FireArmor, sizeof(m_FireArmor));
- ZeroMemory(&m_PoisonArmor, sizeof(m_PoisonArmor));
- ZeroMemory(&m_LightArmor, sizeof(m_LightArmor));
- ZeroMemory(&m_ManaShield, sizeof(m_ManaShield));
- ZeroMemory(&m_PoisonState, sizeof(m_PoisonState));
- ZeroMemory(&m_FreezeState, sizeof(m_FreezeState));
- ZeroMemory(&m_BurnState, sizeof(m_BurnState));
- ZeroMemory(&m_ConfuseState, sizeof(m_ConfuseState));
- ZeroMemory(&m_StunState, sizeof(m_StunState));
- ZeroMemory(&m_LifeState, sizeof(m_LifeState));
- ZeroMemory(&m_ManaState, sizeof(m_ManaState));
- ZeroMemory(&m_DrunkState, sizeof(m_DrunkState));
- }
- void KNpc::CheckTrap()
- {
- if (m_Kind != kind_player)
- return;
-
- if (m_Index <= 0)
- return;
- if (m_SubWorldIndex < 0 || m_RegionIndex < 0)
- return;
- DWORD dwTrap = SubWorld[m_SubWorldIndex].m_Region[m_RegionIndex].GetTrap(m_MapX, m_MapY);
- if (m_TrapScriptID == dwTrap)
- {
- return;
- }
- else
- {
- m_TrapScriptID = dwTrap;
- }
- if (!m_TrapScriptID)
- {
- return;
- }
- Player[m_nPlayerIdx].ExecuteScript(m_TrapScriptID, "main", 0);
- }
- void KNpc::SetFightMode(BOOL bFightMode)
- {
- //g_DebugLog("[DEATH]SetMode:%d", bFightMode);
- m_FightMode = bFightMode;
- #ifdef _SERVER
- if (this->m_Kind == kind_player)
- Player[this->m_nPlayerIdx].m_cPK.CloseAll();
- #endif
- }
- void KNpc::TurnTo(int nIdx)
- {
- if (!Npc[nIdx].m_Index || !m_Index)
- return;
- int nX1, nY1, nX2, nY2;
- GetMpsPos(&nX1, &nY1);
- Npc[nIdx].GetMpsPos(&nX2, &nY2);
- m_Dir = g_GetDirIndex(nX1, nY1, nX2, nY2);
- }
- void KNpc::ReCalcStateEffect()
- {
- KStateNode* pNode;
- pNode = (KStateNode *)m_StateSkillList.GetHead();
- while(pNode)
- {
- if (pNode->m_LeftTime != 0) // 包括被动(-1)和主动(>0)
- {
- int i;
- for (i = 0; i < MAX_SKILL_STATE; i++)
- {
- if (pNode->m_State[i].nAttribType)
- {
- KMagicAttrib MagicAttrib;
- MagicAttrib.nAttribType = pNode->m_State[i].nAttribType;
- MagicAttrib.nValue[0] = -pNode->m_State[i].nValue[0];
- MagicAttrib.nValue[1] = -pNode->m_State[i].nValue[1];
- MagicAttrib.nValue[2] = -pNode->m_State[i].nValue[2];
- ModifyAttrib(m_Index, &MagicAttrib);
- }
- }
- }
- pNode = (KStateNode *)pNode->GetNext();
- }
- }
- #ifndef _SERVER
- extern KTabFile g_ClientWeaponSkillTabFile;
- #endif
- int KNpc::GetCurActiveWeaponSkill()
- {
- int nSkillId = 0;
- if (IsPlayer())
- {
-
- int nDetailType = Player[m_nPlayerIdx].m_ItemList.GetWeaponType();
- int nParticularType = Player[m_nPlayerIdx].m_ItemList.GetWeaponParticular();
-
- //近身武器
- if (nDetailType == 0)
- {
- nSkillId = g_nMeleeWeaponSkill[nParticularType];
- }//远程武器
- else if (nDetailType == 1)
- {
- nSkillId = g_nRangeWeaponSkill[nParticularType];
- }//空手
- else if (nDetailType == -1)
- {
- nSkillId = g_nHandSkill;
- }
- }
- else
- {
- #ifdef _SERVER
- //Real Npc
- return 0;
- #else
- if (m_Kind == kind_player) // No Local Player
- {
- g_ClientWeaponSkillTabFile.GetInteger(m_WeaponType + 1, "SkillId", 0, &nSkillId);
- }
- else //Real Npc
- {
- return 0;//
- }
- #endif
- }
- return nSkillId;
- }
- #ifndef _SERVER
- void KNpc::HurtAutoMove()
- {
- if (this->m_Index != Player[CLIENT_PLAYER_INDEX].m_nIndex)
- return;
- if (this->m_Doing != do_hurt)
- return;
- if (m_sSyncPos.m_nDoing != do_hurt && m_sSyncPos.m_nDoing != do_stand)
- return;
- int nFrames, nRegionIdx;
- nFrames = m_Frames.nTotalFrame - m_Frames.nCurrentFrame;
- if (nFrames <= 1)
- {
- if ((DWORD)SubWorld[0].m_Region[m_RegionIndex].m_RegionID == m_sSyncPos.m_dwRegionID)
- {
- SubWorld[0].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- m_MapX = m_sSyncPos.m_nMapX;
- m_MapY = m_sSyncPos.m_nMapY;
- m_OffX = m_sSyncPos.m_nOffX;
- m_OffY = m_sSyncPos.m_nOffY;
- memset(&m_sSyncPos, 0, sizeof(m_sSyncPos));
- SubWorld[0].m_Region[m_RegionIndex].AddRef(m_MapX, m_MapY, obj_npc);
- }
- else
- {
- nRegionIdx = SubWorld[0].FindRegion(m_sSyncPos.m_dwRegionID);
- if (nRegionIdx < 0)
- return;
- SubWorld[0].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- SubWorld[0].NpcChangeRegion(SubWorld[0].m_Region[m_RegionIndex].m_RegionID, SubWorld[0].m_Region[nRegionIdx].m_RegionID, m_Index);
- m_RegionIndex = nRegionIdx;
- m_dwRegionID = m_sSyncPos.m_dwRegionID;
- m_MapX = m_sSyncPos.m_nMapX;
- m_MapY = m_sSyncPos.m_nMapY;
- m_OffX = m_sSyncPos.m_nOffX;
- m_OffY = m_sSyncPos.m_nOffY;
- memset(&m_sSyncPos, 0, sizeof(m_sSyncPos));
- }
- }
- else
- {
- nRegionIdx = SubWorld[0].FindRegion(m_sSyncPos.m_dwRegionID);
- if (nRegionIdx < 0)
- return;
- int nNpcX, nNpcY, nSyncX, nSyncY;
- int nNewX, nNewY, nMapX, nMapY, nOffX, nOffY;
- SubWorld[0].Map2Mps(m_RegionIndex,
- m_MapX, m_MapY,
- m_OffX, m_OffY,
- &nNpcX, &nNpcY);
- SubWorld[0].Map2Mps(nRegionIdx,
- m_sSyncPos.m_nMapX, m_sSyncPos.m_nMapY,
- m_sSyncPos.m_nOffX, m_sSyncPos.m_nOffY,
- &nSyncX, &nSyncY);
- nNewX = nNpcX + (nSyncX - nNpcX) / nFrames;
- nNewY = nNpcY + (nSyncY - nNpcY) / nFrames;
- SubWorld[0].Mps2Map(nNewX, nNewY, &nRegionIdx, &nMapX, &nMapY, &nOffX, &nOffY);
- _ASSERT(nRegionIdx >= 0);
- if (nRegionIdx < 0)
- return;
- if (nRegionIdx != m_RegionIndex)
- {
- SubWorld[0].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- SubWorld[0].NpcChangeRegion(SubWorld[0].m_Region[m_RegionIndex].m_RegionID, SubWorld[0].m_Region[nRegionIdx].m_RegionID, m_Index);
- m_RegionIndex = nRegionIdx;
- m_dwRegionID = m_sSyncPos.m_dwRegionID;
- m_MapX = nMapX;
- m_MapY = nMapY;
- m_OffX = nOffX;
- m_OffY = nOffY;
- }
- else
- {
- SubWorld[0].m_Region[m_RegionIndex].DecRef(m_MapX, m_MapY, obj_npc);
- m_MapX = nMapX;
- m_MapY = nMapY;
- m_OffX = nOffX;
- m_OffY = nOffY;
- SubWorld[0].m_Region[m_RegionIndex].AddRef(m_MapX, m_MapY, obj_npc);
- }
- }
- }
- #endif
- #ifndef _SERVER
- void KNpc::ProcNetCommand(NPCCMD cmd, int x /* = 0 */, int y /* = 0 */, int z /* = 0 */)
- {
- switch (cmd)
- {
- case do_death:
- DoDeath();
- break;
- case do_hurt:
- DoHurt(x, y, z);
- break;
- case do_revive:
- DoStand();
- m_ProcessAI = 1;
- m_ProcessState = 1;
- SetInstantSpr(enumINSTANT_STATE_REVIVE);
- break;
- case do_stand:
- DoStand();
- m_ProcessAI = 1;
- m_ProcessState = 1;
- default:
- break;
- }
- }
- #endif
- #ifndef _SERVER
- void KNpc::ClearBlood()
- {
- m_nBloodNo = 0;
- m_nBloodAlpha = 0;
- m_nBloodTime = 0;
- m_szBloodNo[0] = 0;
- }
- #endif
- #ifndef _SERVER
- void KNpc::SetBlood(int nNo)
- {
- if (nNo <= 0)
- return;
- m_nBloodNo = nNo;
- m_nBloodAlpha = 0;
- m_nBloodTime = defMAX_SHOW_BLOOD_TIME;
- sprintf(m_szBloodNo, "%d", nNo);
- }
- #endif
- #ifndef _SERVER
- int KNpc::PaintBlood(int nHeightOffset)
- {
- if (!m_szBloodNo[0])
- return nHeightOffset;
- int nHeightOff = nHeightOffset + (defMAX_SHOW_BLOOD_TIME - m_nBloodTime) * defSHOW_BLOOD_MOVE_SPEED;
- int nFontSize = 16;
- DWORD dwColor = SHOW_BLOOD_COLOR | (m_nBloodAlpha << 24);
- int nMpsX, nMpsY;
- GetMpsPos(&nMpsX, &nMpsY);
- g_pRepresent->OutputText(nFontSize, m_szBloodNo, KRF_ZERO_END, nMpsX - nFontSize * g_StrLen(m_szBloodNo) / 4, nMpsY, dwColor, 0, nHeightOff);
- m_nBloodTime--;
- if (m_nBloodTime <= 0)
- {
- ClearBlood();
- return nHeightOff;
- }
- m_nBloodAlpha++;
- if (m_nBloodAlpha > 31)
- m_nBloodAlpha = 31;
- return nHeightOff;
- }
- #endif
- #ifndef _SERVER
- int KNpc::GetNpcPate()
- {
- int nHeight = m_Height + m_nStature;
- if (m_Kind == kind_player)
- {
- if (m_nSex)
- nHeight += 84; //女
- else
- nHeight += 84; //男
- if (m_Doing == do_sit && MulDiv(10, m_Frames.nCurrentFrame, m_Frames.nTotalFrame) >= 8)
- nHeight -= MulDiv(30, m_Frames.nCurrentFrame, m_Frames.nTotalFrame);
-
- if (m_bRideHorse)
- nHeight += 38; //骑马
- }
- return nHeight;
- }
- #endif
- #ifndef _SERVER
- int KNpc::GetNpcPatePeopleInfo()
- {
- int nFontSize = 12;
- if (m_nChatContentLen > 0 && m_nChatNumLine > 0)
- return m_nChatNumLine * (nFontSize + 1);
- int nHeight = 0;
- if (NpcSet.CheckShowLife())
- {
- if (m_Kind == kind_player ||
- m_Kind == kind_partner)
- {
- if (m_CurrentLifeMax > 0 &&
- (relation_enemy == NpcSet.GetRelation(m_Index, Player[CLIENT_PLAYER_INDEX].m_nIndex))
- )
- nHeight += SHOW_LIFE_HEIGHT;
- }
- }
- if (NpcSet.CheckShowName())
- {
- if (nHeight != 0)
- nHeight += SHOW_SPACE_HEIGHT;//好看
- if (m_Kind == kind_player || m_Kind == kind_dialoger)
- nHeight += nFontSize + 1;
- }
- return nHeight;
- }
- #endif