68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#include "GameTown.h"
|
|
#include "Global/Global_Game.h"
|
|
GameTown::GameTown()
|
|
{
|
|
}
|
|
|
|
GameTown::~GameTown()
|
|
{
|
|
}
|
|
|
|
void GameTown::Init(int Index)
|
|
{
|
|
GlobalTownScript::TownConfig *Config = Global_Game::GetInstance().GetTownInfo(Index);
|
|
if (Config)
|
|
{
|
|
this->Name_ = Config->TownName;
|
|
this->Entering_Title = Config->Entering_Title;
|
|
this->Entering_Cutscene = Config->Entering_Cutscene;
|
|
this->NeedLevel = Config->NeedLevel;
|
|
this->NeedQuestID = Config->NeedQuestID;
|
|
// 构造全部地图
|
|
for (auto &it : Config->AreaLst)
|
|
{
|
|
MapInfo info;
|
|
info.Map = new GameMap();
|
|
info.Map->LoadMap(it.second.MapPath);
|
|
info.Type = it.second.MapType;
|
|
MapList_.push_back(info);
|
|
if (info.Type == "gate")
|
|
{
|
|
SariaRoomID = it.first;
|
|
SariaRoomPos = {it.second.GenerateXPos, it.second.GenerateYPos, 0};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void GameTown::AddCharacter(RefPtr<CharacterObject> Chr, int Index)
|
|
{
|
|
int TargetMapIndex = Index;
|
|
|
|
if (Index == -2)
|
|
{
|
|
TargetMapIndex = SariaRoomID;
|
|
}
|
|
// 如果有当前调用中的地图
|
|
if (CurMapIndex != -1)
|
|
{
|
|
RemoveChild(MapList_[CurMapIndex].Map);
|
|
}
|
|
// 如果角色已有父对象
|
|
if (Chr->GetParent())
|
|
{
|
|
Chr->RemoveFromParent();
|
|
}
|
|
// 调用赛利亚房间地图
|
|
AddChild(MapList_[TargetMapIndex].Map);
|
|
if(Index == -2)Chr->SetPosition(SariaRoomPos);
|
|
MapList_[TargetMapIndex].Map->Enter();
|
|
MapList_[TargetMapIndex].Map->AddObject(Chr);
|
|
CurMapIndex = TargetMapIndex;
|
|
}
|
|
|
|
void GameTown::OnUpdate(float DeltaTime)
|
|
{
|
|
Actor::OnUpdate(DeltaTime);
|
|
}
|