📄 dungeon.cpp
字号:
#include "..\stdafx.h"
#include "defaultheader.h"
#include "Citem.h"
#include "scrp_exe.h"
#include "dungeon.h"
#include "ltssupport.h"
#include "skillmgr.h"
#include "AIDefine.h"
#include "UserManager.h"
/////////////////////////////////////////////////
// class CDungeonObject functions
bool CDungeonObject::IsDragonLoad()
{
for( int i=0; i<m_nBossCount; i++ )
{
if( m_pBoss[i].IsDragonLoad() ) return 1;
}
return 0;
}
bool CDungeonObject::SetActive( CHARLIST *ch ) // 贸澜 咀萍宏 瞪 锭
{
if (IsActive())
{
return false;
}
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
ActiveObject();
if (ch)
{
Execute(ch->GetServerID());
}
// 贸澜 茄锅父 秦具 窍绰 青悼 贸府
CDungeonObject *pNewDOb;
switch( m_nExecuteType )
{
case OET_NORMAL_TRAP : // 促弗 仇阑 咀萍宏 矫难 焊磊
{
for( int i=0; i<pDungeonMap->m_nObjectCount; i++ )
{
pNewDOb = &pDungeonMap->m_pObject[i];
if( pNewDOb->m_Index == m_Index+1 )
{
if( pNewDOb->m_nNeedType == ONT_NEED_TRAP2 )
pNewDOb->SetActive( ch );
}
if( pNewDOb->m_nNeedType == ONT_NEED_TRAP )
{
pNewDOb->TryActive( ch );
}
}
break;
}
case OET_POTAL_BOSS :
g_pDungeonMap->InitPotalMember();
CreateScenarioBoss();
break;
case OET_POTAL_DRAGON : // 靛贰帮 肺靛 包访
{
if( pDungeonMap->IsDragonRoad() )
{
g_pDungeonMap->SetVote();
CreateScenarioBoss( CScenarioBoss::NT_DRAGON_LOAD );
}
else
{
CreateScenarioBoss( CScenarioBoss::NT_NORMAL_DRAGON );
}
break;
}
default :
return true;
}
pDungeonMap->SetHistory( ch, this, 0 );
return true;
}
bool CDungeonObject::TryActive( CHARLIST *ch )
{
if( IsActive() ) return false;
bool ret = 0;
CDungeonObject *pNewDOb;
switch( m_nNeedType )
{
case ONT_NEED_ITEM : // 酒捞袍 魄喊肺 累悼矫虐绰 飘乏老 版快
{
if( m_nActiveItemNo )
{
int a, b, c;
if( SearchItemByInv( m_nActiveItemNo, ch, a, b, c ) )
{
ItemAttr *pItem = &ch->inv[a][b][c];
POS pos;
SetItemPos( INV, a, b, c, &pos );
SendDeleteItem( pItem, &pos, ch );
SetActive( ch );
ret = 1;
}
}
break;
}
case ONT_NEED_TRAP :
{
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
ret = 1;
for( int i=0; i<pDungeonMap->m_nObjectCount; i++ )
{
pNewDOb = &pDungeonMap->m_pObject[i];
if( pNewDOb->m_nExecuteType == OET_NORMAL_TRAP )
{
if( !pNewDOb->IsActive() ) // 坷锹 角菩
{
ret = 0;
break;
}
}
}
if( ret ) SetActive( NULL );
break;
}
case ONT_NEED_QUBE :
{
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
int end = 0;
int a, b, c;
while( !end && SearchItemByInv( SIN_TRAP_KEY_7 , ch, a, b, c ) )
{
ItemAttr *pItem = &ch->inv[a][b][c];
POS pos;
SetItemPos( INV, a, b, c, &pos );
SendDeleteItem( pItem, &pos, ch );
if( pDungeonMap->SetTrapKey( 7, ch ) ) end = 1;
}
while( !end && SearchItemByInv( SIN_TRAP_KEY_5 , ch, a, b, c ) )
{
ItemAttr *pItem = &ch->inv[a][b][c];
POS pos;
SetItemPos( INV, a, b, c, &pos );
SendDeleteItem( pItem, &pos, ch );
if( pDungeonMap->SetTrapKey( 5, ch ) ) end = 1;
}
while( !end && SearchItemByInv( SIN_TRAP_KEY_3 , ch, a, b, c ) )
{
ItemAttr *pItem = &ch->inv[a][b][c];
POS pos;
SetItemPos( INV, a, b, c, &pos );
SendDeleteItem( pItem, &pos, ch );
if( pDungeonMap->SetTrapKey( 3, ch ) ) end = 1;
}
break;
}
case ONT_NEED_MONSTER :
{
if( ch->IsPlayer() ) break;
if( ch->npc_index == m_nActiveItemNo )
{
SetActive( NULL );
ret = 1;
}
break;
}
}
return ret;
}
int CDungeonObject::DeleteObjectImage()
{
if( m_ObjectId != -1 )//积己矫挪 坷宏璃飘啊 乐栏搁 昏力 矫挪促.
{
if( GetAttr2( ItemList[m_ObjectId].attr[IATTR_ATTR], IA2_SCENARIO_POTAL ) )
{
RemoveItemList( m_ObjectId );
}
m_ObjectId = -1;
return 1;
}
return 0;
}
void SendDeleteScenarioEventBox( int index )
{
t_packet packet;
packet.h.header.type = CMD_DELETE_MAP_TILE_EVENT;
packet.h.header.size = sizeof( char );
packet.u.kein.default_char = index;
g_pUserManager->SendPacket(&packet); // CSD-CN-031213
}
void CDungeonObject::ActiveObject()
{
m_bActive = true;
m_dwOpenTime = g_curr_time;
if( m_nActiveObjectImage )
{
DWORD attr = IA2_NOTMOVE | IA2_SCENARIO_POTAL | IA2_OPENED;
if( m_nActiveObjectType )
{
attr |= IA2_POISONED; // 飘罚胶肺 嘛绰促.
}
int new_object_id = CreateMapObject( m_nActiveObjectImage, attr, m_nInputX, m_nInputY );
DeleteObjectImage();
m_ObjectId = new_object_id;
if( m_eTileType1 && !m_eTileType2 )
{
::SendDeleteScenarioEventBox( m_Index );
}
else // 货肺 加己捞 父甸绢 脸促搁 弊 荤角阑 傈何俊霸 舅府磊...
{
// 021108 YGI new tile attr
if( m_eTileType2 )
{
::SendTileAttr( m_Index, m_eTileType2, m_nEventNo2, m_nInputX, m_nInputY, m_nRange2, SEND_ALL );
}
}
}
else
{
if( DeleteObjectImage() )
{
// 瘤款霸 乐绰单 货肺 父电霸 绝促搁 傈何俊霸 弊 荤角阑 舅妨霖促.
::SendDeleteScenarioEventBox( m_Index );
}
}
}
bool CDungeonObject::IsThisLayerActive()
{
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
if( pDungeonMap && pDungeonMap->IsActive() ) return true;
return false;
}
int CDungeonObject::CreateNormalBoss()
{
if( IsThisLayerActive() && IsNormalTrap() && !m_pBoss && m_nBoss )
{
m_pBoss = new CScenarioBoss[1];
m_nBossCount = 1;
int x = m_nInputX;
int y = m_nInputY;
if( m_nBossX )
{
x = m_nBossX;
y = m_nBossY;
}
int ret = m_pBoss->CreateBoss( CScenarioBoss::NT_NORMAL_BOSS, m_nBoss, x, y );
if( !ret )
{
SAFE_DELETE_ARRAY(m_pBoss);
m_nBossCount = 0;
return 0;
}
else
{
if( !m_pFollower && m_nFollower )
{
m_pFollower = new CScenarioBoss[m_nFollowerCount];
for( int i=0; i<m_nFollowerCount; i++ )
{
m_pFollower[i].CreateBoss( CScenarioBoss::NT_FOLLOWER, m_nFollower, x+(rand()%5)-3, y+(rand()%5)-3 );
}
}
}
}
return 1;
}
void CDungeonObject::CloseObject( int npc_create_type )
{
m_bActive = false;
if( m_nCloseObjectImage )
{
int new_id = CreateMapObject( m_nCloseObjectImage, IA2_NOTMOVE | IA2_SCENARIO_POTAL, m_nInputX, m_nInputY );
DeleteObjectImage();
m_ObjectId = new_id;
if( m_eTileType2 && !m_eTileType1 )
{
::SendDeleteScenarioEventBox(m_Index);
}
else
{
// 021108 YGI new tile attr
if( m_eTileType1 ) // 货肺 加己捞 积板促搁... 老窜 傈何俊霸 焊辰促.
{
::SendTileAttr( m_Index, m_eTileType1, m_nEventNo1, m_nInputX, m_nInputY, m_nRange1, SEND_ALL );
}
}
if( npc_create_type )
{
CreateNormalBoss();
}
}
else
{
if( DeleteObjectImage() )
{
// 瘤款霸 乐绰单 货肺 父电霸 绝促搁 傈何俊霸 弊 荤角阑 舅妨霖促.
::SendDeleteScenarioEventBox(m_Index);
}
}
// 趣矫 秦具 摧老锭 绢恫 老阑 秦具 且 版快啊 乐促搁 CheckCloseTime() 俊辑
}
int CDungeonObject::Execute( short int cn )
{
CHARLIST *ch = CheckServerId( cn );
if( !ch ) return 0;
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
int ret = 0;
switch( m_nExecuteType )
{
case OET_NORMAL_TRAP :
break;
case OET_POTAL_BOSS :
DeleteScenarioItem( ch );
ret = GotoUser( m_szOutputMap, m_nOutputX, m_nOutputY, cn );
MyLog( 0, "Dungeon Scenario : move user by boss potal [%s]<%s:%d:%d>", ch->Name, m_szOutputMap, m_nOutputX, m_nOutputY );
g_pDungeonMap->AddPotalMember( cn );
break;
case OET_POTAL_OUT_LAYER :
{
// 扁废 鞘夸
DeleteScenarioItem( ch );
int going_time = g_curr_time - m_dwOpenTime;
going_time = m_nTime - going_time;
short int data = going_time/60; // 巢篮 矫埃 (盒)
::SendScenarioMessage( SEND_ALL, SMT_LAYER_POTAL_MESSAGE, &data, sizeof( short ) ); // 割盒 饶俊 促澜 摸捞 凯赋聪促.
ret = GotoUser( m_szOutputMap, m_nOutputX, m_nOutputY, cn );
MyLog( 0, "Dungeon Scenario : move user by layer potal [%s]<%s:%d:%d>", ch->Name, m_szOutputMap, m_nOutputX, m_nOutputY );
break;
}
case OET_POTAL_OUT_DUNGEON :
// 扁废 鞘夸
DeleteScenarioItem( ch );
ret = GotoUser( m_szOutputMap, m_nOutputX, m_nOutputY, cn );
MyLog( 0, "Dungeon Scenario : move user by last layer potal [%s]<%s:%d:%d>", ch->Name, m_szOutputMap, m_nOutputX, m_nOutputY );
break;
case OET_POTAL_DRAGON :
{
DeleteScenarioItem( ch );
ret = GotoUser( m_szOutputMap, m_nOutputX, m_nOutputY, cn );
if( pDungeonMap->IsDragonRoad() )
{
::SendScenarioMessage( cn, SMT_DRAGONROAD_MESSAGE1 ); // 靛贰帮 肺靛狼 富苞 窃膊 蛮馆 皋春 剁款促.
MyLog( 0, "Dungeon Scenario : move user by Red Dragon [%s]<%s:%d:%d>", ch->Name, m_szOutputMap, m_nOutputX, m_nOutputY );
}
else
{
MyLog( 0, "Dungeon Scenario : move user By Gold Dragon [%s]<%s:%d:%d>", ch->Name, m_szOutputMap, m_nOutputX, m_nOutputY );
}
break;
}
}
return ret;
}
int CDungeonObject::CheckCloseTime()
{
if( !m_bActive )
{
if( !m_pBoss ) // 府哩 矫难焊磊
{
if( m_nResenTime != -1 )
{
m_nResenTime --;
if( m_nResenTime == 0 )
{
CreateNormalBoss(); // 吝埃 焊胶甫 府哩 矫虐磊..
m_nResenTime = -1;
}
}
}
return 1;
}
int going_time = g_curr_time - m_dwOpenTime;
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
if( going_time > m_nTime )
{
switch( m_nExecuteType )
{
case OET_POTAL_BOSS :
g_pDungeonMap->GetOutDugeon( CDungeonMapMgr::GOT_END_BOSS_POTAL );
break;
case OET_NORMAL_TRAP :
break;
case OET_POTAL_OUT_LAYER :
{
// 促澜 摸阑 active 矫难霖促.
char data[4];
data[0] = m_nLayer+1;
data[1] = 1;
WORD port = ::GetOwnPort();
memcpy( &data[2], &port, 2 );
SendRegistDungeonMgrServer( CDungeonBasic::TYPE_STATUS_REGIST, data, 4 );
g_pDungeonMap->GetOutDugeon( CDungeonMapMgr::GOT_END_LAYER ); // 促 泼败 滚赴促.
break;
}
case OET_POTAL_OUT_DUNGEON :
break;
case OET_POTAL_DRAGON :
g_pDungeonMap->ScenarioFightProc( this );
break;
}
if( m_nNeedType != ONT_NEED_DRAGON ) // ONT_NEED_DRAGON 篮 矫埃俊 狼秦 close 登绰霸 酒聪促.
{
CloseObject();
pDungeonMap->SetHistory( NULL, this, 0 );
return 1;
}
}
return 0;
}
int CDungeonObject::Start() // 盖贸澜 技泼
{
CloseObject( 0 );
return 1;
}
CDungeonObject::~CDungeonObject()
{
if(DeleteObjectImage())
{
t_packet packet;
packet.h.header.type = CMD_DELETE_MAP_TILE_EVENT;
packet.h.header.size = sizeof( char );
packet.u.kein.default_char = m_Index;
g_pUserManager->SendPacket(&packet); // CSD-CN-031213
}
SAFE_DELETE_ARRAY(m_pBoss);
m_nBossCount = 0;
SAFE_DELETE_ARRAY(m_pFollower);
}
int CDungeonObject::KillBoss( CHARLIST *user, CHARLIST *boss )
{
// 矫唱府坷 阁胶磐啊 磷菌促搁... 竣萍宏甫 畴妨夯促.
CDungeonMap* pDungeonMap = (CDungeonMap *)m_pMother;
for( int i=0; i<pDungeonMap->m_nObjectCount; i++ )
{
if( pDungeonMap->m_pObject[i].m_nNeedType == ONT_NEED_MONSTER )
{
pDungeonMap->m_pObject[i].TryActive( boss );
}
}
if (m_pBoss && m_pBoss->m_nNpcIndex == boss->GetServerID())
{
// 皋矫瘤
switch( m_pBoss->GetBossType() )
{
case m_pBoss->BT_LAYER_BOSS :
{
k_invite_colossus_map data;
data.port = boss->SprNo;
strcpy( data.name, user?user->Name:"" );
::SendScenarioMessage(SEND_ALL, SMT_KILL_BOSS, &data, sizeof( k_invite_colossus_map ) );
// 030211 YGI
MyLog( 0, "[Dungeon] Kill LAYER_BOSS, sprno : [%d], killer:[%s]", boss->SprNo, user?user->Name:" " );
break;
}
case m_pBoss->BT_DARAGON :
case m_pBoss->BT_DARAGON_HEART :
{
k_invite_colossus_map data;
data.port = boss->SprNo;
strcpy( data.name, user?user->Name:"" );
::SendScenarioMessage(SEND_ALL, SMT_KILL_BOSS, &data, sizeof( k_invite_colossus_map ) );
// 030211 YGI
MyLog( 0, "[Dungeon] Kill Dragon, sprno : [%d], killer:[%s]", boss->SprNo, user?user->Name:" " );
if( pDungeonMap->IsDragonRoad() )
{
// 靛贰帮 肺靛啊 磷菌促.
SendScenarioMessage(SEND_ALL, SMT_DRAGONROAD_MESSAGE6 );
// 茄 仇阑 榜扼辑 靛贰帮 浇饭捞绢肺 父甸磊...
}
pDungeonMap->SetDragonRoad(); // 促澜锅浚 靛贰帮 肺靛牢瘤 汲沥 窍磊..
break;
}
default :
{
// 府力 炼沥
m_nResenTime = 3; // 3盒
break;
}
}
SAFE_DELETE_ARRAY(m_pBoss);
m_pBoss = 0;
m_nBossCount = 0;
if( m_nBossItem )
{
ItemAttr item = ::GenerateItem( m_nBossItem );
if( !item.item_no ) return 0;
for( int i=0; i<3; i++ ) // 3俺 冻迸 霖促.
DropItem( boss->X + (rand()%100)-50, boss->Y +(rand()%100)-50, &item);
return 1;
}
}
return 0;
}
int CDungeonObject::CreateScenarioBoss( int boss_type )
{
switch( boss_type )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -