EID EntityManager::CreateNPC(PID npcID, bool updateProxList, bool alwaysWatching) { psCharacter *chardata=psServer::CharacterLoader.LoadCharacterData(npcID,false); if (chardata==NULL) { CPrintf(CON_ERROR, "Couldn't load character for NPC %s.", ShowID(npcID)); return 0; } return CreateNPC(chardata, updateProxList, alwaysWatching); }
EID EntityManager::CreateNPC(psCharacter *chardata, bool updateProxList, bool alwaysWatching) { csVector3 pos; float yrot; psSectorInfo *sectorinfo; iSector *sector; InstanceID instance; chardata->GetLocationInWorld(instance, sectorinfo,pos.x,pos.y,pos.z,yrot); sector = FindSector(sectorinfo->name); if (sector == NULL) { Error3("Could not resolve sector >%s< for NPC %s.", sectorinfo->name.GetData(), ShowID(chardata->GetPID())); delete chardata; return false; } return CreateNPC(chardata, instance, pos, sector, yrot, updateProxList, alwaysWatching); }
void EntityManager::RemoveRideRelation(gemActor *rider) { csVector3 pos; float yrot; psSectorInfo *sectorinfo; InstanceID instance; float movMod = rider->GetMount()->GetRaceInfo()->GetSpeedModifier(); rider->GetCharacterData()->GetLocationInWorld(instance, sectorinfo,pos.x,pos.y,pos.z,yrot); rider->GetMount()->SetLocationInWorld(instance, sectorinfo,pos.x,pos.y,pos.z,yrot); CreateNPC(rider->GetMount()); rider->SetMount(NULL); rider->UpdateProxList( true ); if( movMod != rider->GetCharacterData()->GetRaceInfo()->GetSpeedModifier()) { psMoveModMsg modMsg(rider->GetClientID(), psMoveModMsg::NONE, csVector3(0), 0); modMsg.SendMessage(); } }
CChar * CChar::Use_Figurine( CItem * pItem, bool bCheckFollowerSlots ) { ADDTOCALLSTACK("CChar::Use_Figurine"); // NOTE: The figurine is NOT destroyed. bool bCreatedNewNpc = false; if ( !pItem ) return NULL; if ( pItem->m_uidLink.IsValidUID() && pItem->m_uidLink.IsChar() && pItem->m_uidLink != GetUID() && !IsPriv(PRIV_GM) ) { SysMessageDefault(DEFMSG_MSG_FIGURINE_NOTYOURS); return NULL; } // Create a new NPC if there's no one linked to this figurine CChar *pPet = pItem->m_itFigurine.m_UID.CharFind(); if ( !pPet ) { CREID_TYPE id = pItem->m_itFigurine.m_ID; if ( !id ) { id = CItemBase::FindCharTrack(pItem->GetID()); if ( !id ) { DEBUG_ERR(("FIGURINE id 0%x, no creature\n", pItem->GetDispID())); return NULL; } } bCreatedNewNpc = true; pPet = CreateNPC(id); ASSERT(pPet); pPet->SetName(pItem->GetName()); if ( pItem->GetHue() ) { pPet->m_prev_Hue = pItem->GetHue(); pPet->SetHue(pItem->GetHue()); } } if ( bCheckFollowerSlots && IsSetOF(OF_PetSlots) ) { if ( !FollowersUpdate(pPet, static_cast<short>(maximum(1, pPet->GetDefNum("FOLLOWERSLOTS", true, true))), true) ) { SysMessageDefault(DEFMSG_PETSLOTS_TRY_CONTROL); if ( bCreatedNewNpc ) pPet->Delete(); return NULL; } } if ( pPet->IsDisconnected() ) pPet->StatFlag_Clear(STATF_Ridden); // pull the creature out of IDLE space pItem->m_itFigurine.m_UID.InitUID(); pPet->m_dirFace = m_dirFace; pPet->NPC_PetSetOwner(this); pPet->MoveToChar(pItem->GetTopLevelObj()->GetTopPoint()); pPet->Update(); pPet->Skill_Start(SKILL_NONE); // was NPCACT_RIDDEN pPet->SoundChar(CRESND_RAND1); return pPet; }