📄 objectengine.cpp
字号:
#include "stdafx.h"
#define _RANGE_X 12
#define _RANGE_Y 12
#define _CACHE_TICK 500
#define HEALTHFILLTICK 1500
#define SPELLFILLTICK 800
CMagicInfo* GetMagicInfo(int nMagicID);
CMirMap* GetMap(char *pszMapName);
CMonsterObject* AddCreature(CMirMap* pMap, int nX, int nY, int nMonRace, BOOL fSearch);
CCharObject::CCharObject(CUserInfo* pUserInfo)
{
// InitializeCriticalSection(&m_cs);
m_pUserInfo = pUserInfo;
m_nCurrX = 0;
m_nCurrY = 0;
ZeroMemory(m_szName, sizeof(m_szName));
m_dwHealthTick = 0;
m_dwSpellTick = 0;
m_dwTickSec = 0;
m_fOpenHealth = FALSE;
m_nCharStatusEx = 0;
m_nCharStatus = 0;
m_IncHealing = 0;
m_IncHealth = 0;
m_IncSpell = 0;
m_btPerHealing = 5;
m_btPerHealth = 5;
m_btPerSpell = 5;
m_dwIncHealthSpellTime = 0;
m_dwTickSec = GetTickCount();
m_nEvent = -1; // No Event
ZeroMemory(m_wStatusArr, sizeof(m_wStatusArr));
ZeroMemory(m_szName, sizeof(m_szName));
m_sHitSpeed = 0;
m_fAbilMagBubbleDefence = FALSE;
m_btMagBubbleDefenceLevel = 0;
m_fInspector = FALSE;
m_fFastTrain = FALSE;
m_IncHealth = 0;
m_IncSpell = 0;
m_fIsGhost = FALSE;
m_fIsNeverDie = FALSE;
m_btSpeedPoint = DEFSPEED;
m_fHumHideMode = FALSE;
m_fFixedHideMode = FALSE;
m_fStoneMode = FALSE;
m_fStickMode = FALSE;
m_pMasterObject = NULL;
m_pTargetObject = NULL;
}
CCharObject::~CCharObject()
{
PLISTNODE pListNode = m_xVisibleObjectList.GetHead();
while (pListNode)
{
CVisibleObject* pVisibleObject = m_xVisibleObjectList.GetData(pListNode);
if (pVisibleObject)
{
delete pVisibleObject;
pVisibleObject = NULL;
}
pListNode = m_xVisibleObjectList.RemoveNode(pListNode);
} // while (pListNode)
// DeleteCriticalSection(&m_cs);
}
void CCharObject::SelectTarget(CCharObject* pTargetObject)
{
m_pTargetObject = pTargetObject;
m_dwTargetFocusTime = GetTickCount();
}
void CCharObject::GetFrontPosition(int &nX, int &nY)
{
int nHeight = m_pMap->m_stMapFH.shHeight;
int nWidth = m_pMap->m_stMapFH.shWidth;
nX = m_nCurrX;
nY = m_nCurrY;
switch (m_nDirection)
{
case DR_UP:
if (nY > 0) nY--;
break;
case DR_DOWN:
if (nY < nHeight - 1) nY++;
break;
case DR_LEFT:
if (nX > 0) nX--;
break;
case DR_RIGHT:
if (nX < nWidth - 1) nX++;
break;
case DR_UPLEFT:
{
if (nX > 0 && nY > 0)
{
nX--;
nY--;
}
break;
}
case DR_UPRIGHT:
{
if (nX > 0 && nY < nHeight - 1)
{
nX++;
nY--;
}
break;
}
case DR_DOWNLEFT:
{
if (nX < nWidth - 1 && nY > 0)
{
nX--;
nY++;
}
break;
}
case DR_DOWNRIGHT:
{
if (nX < nWidth - 1 && nY < nHeight - 1)
{
nX++;
nY++;
}
break;
}
}
}
int CCharObject::GetBack(int nDirection)
{
switch (nDirection)
{
case DR_UP:
return DR_DOWN;
case DR_DOWN:
return DR_UP;
case DR_LEFT:
return DR_RIGHT;
case DR_RIGHT:
return DR_LEFT;
case DR_UPLEFT:
return DR_DOWNRIGHT;
case DR_UPRIGHT:
return DR_DOWNLEFT;
case DR_DOWNLEFT:
return DR_UPRIGHT;
case DR_DOWNRIGHT:
return DR_UPLEFT;
}
return nDirection;
}
BOOL CCharObject::GetBackPosition(int &nX, int &nY)
{
int nHeight = m_pMap->m_stMapFH.shHeight;
int nWidth = m_pMap->m_stMapFH.shWidth;
nX = m_nCurrX;
nY = m_nCurrY;
switch (m_nDirection)
{
case DR_UP:
if (nY < nHeight - 1) nY++;
break;
case DR_DOWN:
if (nY > 0) nY--;
break;
case DR_LEFT:
if (nX < nWidth - 1) nX++;
break;
case DR_RIGHT:
if (nX > 0) nX--;
break;
case DR_UPLEFT:
if ((nX < nWidth - 1) && (nY < nHeight - 1))
{
nX++;
nY++;
}
break;
case DR_UPRIGHT:
if ((nX < nWidth - 1) && (nY > 0))
{
nX--;
nY++;
}
break;
case DR_DOWNLEFT:
if ((nX > 0) && (nY < nHeight - 1))
{
nX++;
nY--;
}
break;
case DR_DOWNRIGHT:
if ((nX > 0) && (nY > 0))
{
nX--;
nY--;
}
break;
}
return TRUE;
}
BOOL CCharObject::IsProperTarget(CCharObject* pTargetObject)
{
// if target.BoSysopMode or target.BoStoneMode then //款康磊...
// Result := FALSE;
return TRUE;
}
BOOL CCharObject::IsFriend(CCharObject* pCharObject)
{
if (pCharObject->m_wObjectType & _OBJECT_HUMAN)
{
if (pCharObject->m_pUserInfo)
{
switch (pCharObject->m_pUserInfo->GetAttackMode())
{
case HAM_ALL:
return TRUE;
case HAM_PEACE:
return TRUE;
}
}
}
/* function IsFriend (cret: TCreature): Boolean;
begin
Result := FALSE;
if cret.RaceServer = RC_USERHUMAN then begin //措惑捞 荤恩牢 版快父
//傍拜屈怕 汲沥俊 蝶扼 促抚
case HumAttackMode of
HAM_ALL: Result := TRUE;
HAM_PEACE: Result := TRUE;
HAM_GROUP:
begin
if cret = self then
Result := TRUE;
if IsGroupMember (cret) then
Result := TRUE;
end;
HAM_GUILD:
begin
if cret = self then
Result := TRUE;
if MyGuild <> nil then begin
if TGuild(MyGuild).IsMember(cret.UserName) then
Result := TRUE;
if BoGuildWarArea and (cret.MyGuild <> nil) then begin //巩颇傈,傍己傈 瘤开俊 乐澜
if TGuild(MyGuild).IsAllyGuild(TGuild(cret.MyGuild)) then
Result := TRUE;
end;
end;
end;
HAM_PKATTACK:
begin
if cret = self then Result := TRUE;
if PKLevel >= 2 then begin //郴啊 弧盎捞
if cret.PKLevel < 2 then Result := TRUE;
end else begin //郴啊 闰嫡捞
if cret.PKLevel >= 2 then Result := TRUE;
end;
end;
end;
end;
end;
*/
return FALSE;
}
BOOL CCharObject::IsProperFriend(CCharObject* pCharObject)
{
BOOL fFlag = FALSE;
if (pCharObject)
{
if (m_wObjectType & _OBJECT_ANIMAL)
{
if (pCharObject->m_wObjectType & _OBJECT_ANIMAL)
fFlag = TRUE;
if (pCharObject->m_pMasterObject)
fFlag = FALSE;
}
else
{
if (m_wObjectType & _OBJECT_HUMAN)
{
fFlag = IsFriend(pCharObject);
if (pCharObject->m_wObjectType & _OBJECT_ANIMAL)
{
if (pCharObject->m_pMasterObject == this)
fFlag = TRUE;
else if (pCharObject->m_pMasterObject)
fFlag = IsFriend(pCharObject->m_pMasterObject);
}
}
else
fFlag = TRUE;
}
}
return fFlag;
}
UINT CCharObject::GetCharStatus()
{
UINT s = 0;
for (int i = 0; i < MAX_STATUS_ATTRIBUTE; i++)
{
if (m_wStatusArr[i] > 0)
s |= (0x80000000 >> i);
}
return (s | (m_nCharStatusEx & 0x000FFFFF));
}
BOOL CCharObject::RestoreHealSpell()
{
if (m_fIsNeverDie)
{
m_WAbility.HP = m_WAbility.MaxHP;
m_WAbility.MP = m_WAbility.MaxMP;
}
int n = (GetTickCount() - m_dwTickSec) / 20; //檬寸 50
m_dwTickSec = GetTickCount();
m_dwHealthTick += n;
m_dwSpellTick += n;
if (!m_fIsDead)
{
int nPlus = 0;
BOOL fHealthSpellChanged = FALSE;
if (m_WAbility.HP < m_WAbility.MaxHP)
{
if (m_dwHealthTick >= HEALTHFILLTICK)
{
nPlus = m_WAbility.MaxHP / 15 + 1;
if (m_WAbility.HP + nPlus < m_WAbility.MaxHP)
m_WAbility.HP = m_WAbility.HP + nPlus;
else
m_WAbility.HP = m_WAbility.MaxHP;
fHealthSpellChanged = TRUE;
}
}
if (m_WAbility.MP < m_WAbility.MaxMP)
{
if (m_dwSpellTick >= SPELLFILLTICK)
{
nPlus = m_WAbility.MaxMP / 18 + 1;
if (m_WAbility.MP + nPlus < m_WAbility.MaxMP)
m_WAbility.MP = m_WAbility.MP + nPlus;
else
m_WAbility.MP = m_WAbility.MaxMP;
fHealthSpellChanged = TRUE;
}
}
if (m_WAbility.HP == 0)
{
return TRUE;
}
/* if WAbil.HP = 0 then begin
if BoAbilRevival then begin //犁积 瓷仿捞 乐促.
if GetTickCount - LatestRevivalTime > 60 * 1000 then begin
LatestRevivalTime := GetTickCount;
//馆瘤甫 粹霸 茄促.
ItemDamageRevivalRing;
WAbil.HP := WAbil.MaxHP;
HealthSpellChanged;
SysMsg ('馆瘤狼 塞栏肺 个捞 犁积登菌嚼聪促.', 1);
end;
end;
if WAbil.HP = 0 then
Die;
end; */
if (fHealthSpellChanged)
HealthSpellChanged();
if (m_dwHealthTick >= HEALTHFILLTICK)
m_dwHealthTick = 0;
if (m_dwSpellTick >= SPELLFILLTICK)
m_dwSpellTick = 0;
}
else
{
if (GetTickCount() - m_dwDeathTime > 3 * 60 * 1000)
MakeGhost();
return FALSE;
}
if ((!m_fIsDead) && (m_IncSpell > 0) || (m_IncHealth > 0) || (m_IncHealing > 0))
{
int nHP = 0, nMP = 0;
DWORD inchstime = 600 - _MIN(400, m_Ability.Level * 10);
if (GetTickCount() - m_dwIncHealthSpellTime >= inchstime)
{
n = _MIN(200, (GetTickCount() - m_dwIncHealthSpellTime) - inchstime);
m_dwIncHealthSpellTime = GetTickCount() + n;
if ((m_IncSpell > 0) || (m_IncHealth > 0) || (m_IncHealing > 0))
{
if (m_btPerHealing <= 0) m_btPerHealing = 1;
if (m_btPerSpell <= 0) m_btPerSpell = 1;
if (m_btPerHealth <= 0) m_btPerHealth = 1;
if (m_IncHealth < m_btPerHealth)
{
nHP += m_IncHealth;
m_IncHealth = 0;
}
else
{
nHP += m_btPerHealth;
m_IncHealth = m_IncHealth - m_btPerHealth;
}
if (m_IncSpell < m_btPerSpell)
{
nMP += m_IncSpell;
m_IncSpell = 0;
}
else
{
nHP += m_btPerSpell;
m_IncSpell = m_IncSpell - m_btPerSpell;
}
if (m_IncHealing < m_btPerHealing)
{
nHP += m_IncHealing;
m_IncHealing = 0;
}
else
{
nHP += m_btPerHealing;
m_IncHealing = m_IncHealing - m_btPerHealing;
}
}
m_btPerHealing = 5;
m_btPerHealth = 5 + (m_Ability.Level / 10);
m_btPerSpell = 5 + (m_Ability.Level / 10);
IncHealthSpell(nHP, nMP);
if (m_WAbility.HP == m_WAbility.MaxHP)
{
m_IncHealth = 0;
m_IncHealing = 0;
}
if (m_WAbility.MP == m_WAbility.MaxMP)
m_IncSpell = 0;
}
}
else
m_dwIncHealthSpellTime = GetTickCount();
if ((int)m_dwHealthTick < -HEALTHFILLTICK)
{
if (m_WAbility.HP > 1)
{
m_WAbility.HP--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -