mirror of
https://github.com/UOX3DevTeam/UOX3
synced 2026-08-13 12:27:04 -04:00
Fixed an issue where the color of NPC corpse names would not always match up with the NPC's flag color Fixed a bug where the baseRange and maxRange properties of ranged weapons would not get saved to world files. These values are now saved in the format of RANGE=baseRange,maxRange Changed the way items are added to containers, to ensure that the order in which the items are displayed to the player always reflects the order in which they were added; now the most recent item added/moved in a container will always be rendered on top of older items. Made adjustments to how items are randomly added to containers; should use more of a given container gump's available area now Exposed Item property to JS engine, which contains serial of the creator of an item: .creator // contains serial of the creator of an item. If set, maker's marks will show up in the item's tooltip Fixed an issue where JS engine would lose track of script context if one script used CreateDFNItem() or SpawnNPC() functions and the new objects had events that triggered upon creation. UOX3 now restores the original script context at the tail end of these functions. Added new JS Event to allow inserting custom tooltip text for objects, which will be displayed in tooltips right after the object name. Any text returned from the event will be displayed, and the text can make use of the same HTML tags as gumps to make changes to color, font, etc. onTooltip( myObj ) // Triggers for objects right before the object's tooltip properties are sent to client Updated 'tweak and 'set commands to refresh item being modified if movable state of item changes, so the change is reflected in nearby clients Fixed an issue with NPC vendors and items bought from players not being properly removed from the vendor's "bought container" when players buy them again Ported Item Identification skill from code to JS (js/skill/itemid.js) and removed hard-coded version Implemented magic item generator in JS (js/item/magic_item.js). When this script is attached to an NPC, it has a chance to generate magic weapons, armors, wands/staffs and rings as loot on the NPC's corpse when slain. The chance of getting quality magical items increases with the fame level of the NPC in question. The types of magical items generated follows the pattern of such items as implemented in UO prior to the AoS expansion. Examples: exceedingly accurate war hammer of vanquishing substantial, accurate axe of power and Daemon's Breath silver long sword massive platemail arms of Protection metal shield of defense durable ringmail tunic of guarding All magic items have a chance to have spell effects attached (with rings/wands being guaranteed to have these), with a limited amount of charges available. For weapons, these effects activate on successful hits in combat, while for armors they activate on equip, and then periodically as long as the item is worn. Rings and wands/staffs have to be manually activated and targeted - with the exception of rings of invisibility, which activate the moment you equip them! Related scripts: js/item/magic_armor_equipeffects.js js/item/magic_weapon_accbonus.js js/item/magic_weapon_equip.js js/item/magic_weapon_spell_attack.js The magic item loot generation script has been attached to a number of different NPCs, all of which now have a chance to drop magic items as loot when defeated. A bonus magical item - the glacial staff - has also been implemented (js/item/magic_glacial_staff.js), and has a chance to drop as loot from Giant Ice Serpents! Fixed an issue with CustomTarget where the target message would not be displayed if the cursorType parameter was provided Fixed bug with 'rename command, which referenced a non-existing variable that caused a script crash Added additional object properties to 'get and 'set commands: .shouldSave // Determines if an item should be saved in worldfiles or not .baseRange // Determines the base range of a ranged weapon, less than which it becomes less effective .maxRange // Determines the max range of a ranged weapon, beyond which it cannot reach its target The feature that allows stats like Strength, Dexterity and Intelligence to provide bonuses to skill checks has been turned into a UOX.INI setting, which is disabled by default. The bonuses have also been nerfed; they will no longer contribute more to the success of a skill check than the actual skill being checked! STATSAFFECTSKILLCHECKS=0/1 // If enabled, stats can provide bonuses to skill checks based on the weighting for those stats as setup in dfndata/skills/skills.dfn Updated damage tracking code to include the type of damage that was dealt (PHYSICAl vs HEAT vs COLD, etc) Updated Character JS Method Damage() to include a new parameter that can specify the type of damage that was dealt to the character. The new parameter must always be included if other optional parameters are used. Note that updates might be required for scripts making use of this method.Updated syntax: .Damage( amount ) .Damage( amount, damageType ) .Damage( amount, damageType, attacker ) .Damage( amount, damageType, attacker, doRepsys ) Supported damageTypes: PHYSICAL = 1 LIGHT = 2 RAIN = 3 COLD = 4 HEAT = 5 LIGHTNING = 6 // magic damage POISON = 7 SNOW = 8 Updated JS Event OnDamage to include an additional parameter that describes the type of damage that was dealt. New syntax: onDamage( damaged, attacker, damageValue, damageType ) Updated JS Event OnSpellTarget to allow rejecting a spell being cast on a target by returning a value of 2 from the script Split the character priv flag for magic reflection into a temporary one (one-time magic reflection spell) and a permanent one (innate permanent reflection ability). The temporary effect is put in place by Magic Reflection spell, and is removed after a successful spell reflect. The permanent one is an innate ability of a character and is not removed even after a spell is reflected. Added new Character JS property to get/set state of a character's permanent magic reflect ability: .permanentMagicReflect // 0 = disable, 1 = enable Added special abilities/effects for the following NPCs: Acid Elementals now have a chance to damage the melee weapons of their attackers Dull Copper Elementals now explode on death Shadow Iron Elemental is immune to targeted spell damage Copper Elementals have permanent magic reflect, and reflect some physical damage back at their attacker Bronze Elementals deal passive area damage to nearby players every 5 to 10 seconds Valorite Elementals have permanent magic reflect, reflect some physical damage back at their attacker Snow/Ice Elementals deal passive area damage to nearby players every 5 to 10 seconds Lava Serpents deal passive area damage to nearby players every 5 to 10 seconds Phoenixes deal passive area damage to nearby players every 5 to 10 seconds Pixies have a chance to cast a random spell upon receiving a death blow: Bless (target) Curse (target) Explosion (target) Greater Poison (target) Greater Heal (self, prevents death) Ethereal Warriors will now resurrect dead players with positive karma Ethereal Warriors now have a chance to drain target's health, stamina or mana on hit Fire Breath special ability added to the following NPCs, with the random ability damage scaling with the NPCs current health: Hell Cat, 5 to 8 dmg at max health Fire Steed, 6 to 9 dmg at max health Hell Hounds, 8 to 11 dmg at max health Lava Lizard, 8 to 11 dmg at max health Predator Hell Cat, 9 to 14 dmg at max health Sea Serpent, 11 to 17 dmg at max health Swamp Dragon, 15 to 22 dmg at max health Armored Swamp Dragon, 15 to 22 dmg at max health Fire Gargoyle, 20 to 30 dmg at max health Deep Sea Serpent, 21 to 32 dmg at max health Serpentine Dragon, 22 to 32 dmg at max health Drake (Gray), 22 to 32 dmg at max health Drake (Red), 22 to 32 dmg at max health Nightmare, 26 to 39 dmg at max health Dark Steed, 26 to 39 dmg at max health Silver Steed, 26 to 39 dmg at max health Kraken, 39 to 59 dmg at max health Dragon (Red), 41 to 62 dmg at max health Dragon (Gray), 41 to 62 dmg at max health Shadow Wyrm, 50 to 75 dmg at max health Reptalon, 51 to 77 dmg at max health Skeletal Dragon, 52 to 77 dmg at max health Ancient Wyrm, 60 to 90 dmg at max health Update stats, skills and loot for all currently implemented NPCs Removed an ancient piece of code that prevented corpses from being generated for various elementals and blade spirits on death. This was originally put in place because these creatures had no corpses, and would replace it with a backpack instead, but these creatures now all have corpses in all client versions supported by UOX3 Updated potions script (js/item/potion.js) with updated formula for amount of hitpoints healed by healing potions, and added restrictions for using them when at full health and/or if poisoned (Dragon Slayer) Fixed a bug where creatures (and humans, if FORCENEWANIMATIONPACKET was disabled in uox.ini) would play animations with wrong frame count, causing the animations to either freeze for a few frames at the end, or get cut off a couple of frames early Implemented bonus hit chance for Archery skill, based on mention of such a bonus in Publish 5 patch notes and related UO House of Commons chat. This has been exposed as a UOX.INI setting where this bonus can be tweaked: ARCHERYHITBONUS=10 // Bonus hit chance for Archery skill added to regular hit chance in combat. Defaults to 10% Implemented optional extra delay between moving and being able to shoot with ranged weapons in combat (in addition to whatever delay is there due to speed of the ranged weapon). This is exposed as a UOX.INI setting: ARCHERYSHOOTDELAY=0.5 // Minimum delay in seconds from a player stops moving until they can start to fire their ranged weapon. Defaults to 0.5s Fixed a bug where players who never entered combat mode could fire ranged weapons while moving Updated Add-menu with some improvements for usability: Menu now directly on the Objects (previously "Shard") tab for quicker access, with a small welcome text and quick-link button for UOX3 docs Settings tab contains some (persistent, will be saved with character) options for how the Add-menu behaves, along with a few quick-access buttons to some useful commands. Available options: Option to add chosen item at specific location instead of in GM's backpack Option to add chosen item repeatedly until cancelled Option to automatically reopen Add-menu on last menu that was open when a selection is made Option to force decayable state of all added items to either off (doesn't decay), on (decays) or nothing (use item default) Option to force movable state of all added items to either off (not movable), on (movable) or nothing (use item default) Added a Home button at the bottom of the menu, that takes the user back to the front page of the Add-menu regardless of which menu page they're on Updated Character/Socket JS Method SysMessage() with an optional parameter to specify the color used to display the system message. Updated syntax: .SysMessage( "Text" ) // Display "Text" to user as a system message with default system message color from ini .SysMessage( "Text %s %s", txtArg1, txtArg2 ) // Display "Text" to player with string arguments injected into text .SysMessage( txtColor, "Text" ) // Display "Text" to user with a specified color .SysMessage( txtColor, "Text %s %s", txtArg1, txtArg2 ) // Combination of text color, text and string arguments Fixed a bug where hair/beard items could show up inside corpses Fixed a bug where items could sometimes vanish (visually) from containers when bouncing back because player was not able to pick them up Fixed a bug where players would be unable to pick up a freely movable item from a locked down container Updated handling of item bouncing on pickup to use UOX3 dictionary messages instead of hard-coded client messages Added support for new Dictionary language: dictionary.POL - Polish (SERVERLANGUAGE=8 in uox.ini, or client language 83 if SERVERLANGUAGE is set to 0) Added taming restrictions for Unicorn, Ki-Rin and Cu Sidhe (js/skill/taming.js) Added modification of some creatures stats after they've been tamed (js/skill/taming.js) Added restrictions for who can ride certain creatures (Unicorn, Ki-Rin, Cu Sidhe) Updated words of power for Meteor Swarm spell to follow the same logic as other spells using Kal (Summon): Kal Des Flam Ylem Added new Item/Character JS Methods to get/set temporary custom tags which don't persist across worldsaves (or across reconnects, for players): .GetTempTag( "tagName" ) .SetTempTag( "tagName", tagValue ) When applying HPMAX, STAMINAMAX AND MANAMAX DFN tags to new NPCs, their current HP, STAMINA and MANA properties will now be automatically updated to match Fixed a server crash caused by empty speech messages sent from certain clients Fixed a bug that prevented teleport locations in Felucca/Trammel from working properly Updated calculations in code for duration and damage of existing poison strengths (1 - Lesser, 2 - Normal, 3 - Greater, 4 - Deadly) to match with ~Publish 15 (LBR/pre-AoS), and added another poison strength for monster usage (5 - Lethal) The strength of the Poison and Poison Field spells is now based on the average of the caster's Magery and Poisoning skills, the distance from the target (Poison spell only) and the target's Resisting Spells skill. If caster is further away than 2 tiles from target, the poison strength always equals Lesser Poison, otherwise the following rules apply: If caster's combined skill is higher than 100.0, poison strength equals Greater Poison, with 5% chance of Deadly Poison (if Poison spell) or Deadly Poison (if Poison Field spell) If caster's combined skill is higher than 70.2, poison strength equals Greater Poison If caster's combined skill is higher than 30.2, poison strength equals Normal Poison If caster's combined skill is 30.2 or lower, poison strength equals Lesser Poison If target resists spell, poison strength is reduced by 1 level, unless it's already at the lowest level Fixed an issue that would would let players move faster than they should have been allowed to Fixed misc issues with Party System: Mana and Stamina should now update for Party Members when added to the party, when going in/out of range and when their stats update while in range Players who get disconnected or relog should now find themselves back in the same party they were in previously Added system messages to inform party members about updates to their party, and to let invited players know they've successfully joined a party (or rejoined, if relogging) World saves now operate on the principle of only saving changes done since the last world save. Combined with the fact that NPCs in UOX3 are only active if there are players in the same/neighbouring map regions, shard owners may expect to see a decrease in world save times ranging from ~11% to ~99%, depending on how active and how spread out their player base is. If no changes have taken place since last save, saves are virtually instantaneous!
657 lines
20 KiB
C++
657 lines
20 KiB
C++
#include "uox3.h"
|
||
#include "speech.h"
|
||
#include "cVersionClass.h"
|
||
#include "cRaces.h"
|
||
#include "commands.h"
|
||
#include "skills.h"
|
||
#include "CJSMapping.h"
|
||
#include "cScript.h"
|
||
#include "cEffects.h"
|
||
#include "CPacketSend.h"
|
||
#include "CResponse.h"
|
||
#include "movement.h"
|
||
#include "Dictionary.h"
|
||
#include "StringUtility.hpp"
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - void ClilocMessage( CSocket *mSock, SpeechType speechType, UI16 hue, UI16 font, UI32 messageNum, const char *types = "", ... )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Sends a cliloc message to the client, which is displayed as a system message
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
void ClilocMessage( CSocket *mSock, SpeechType speechType, UI16 hue, UI16 font, UI32 messageNum, const char *types = "", ... )
|
||
{
|
||
bool multipleArgs = false;
|
||
std::string argList = "";
|
||
std::string stringVal = "";
|
||
const char *typesPtr = types;
|
||
|
||
va_list marker;
|
||
va_start( marker, types );
|
||
while( *typesPtr != '\0' )
|
||
{
|
||
if( *typesPtr == 'i' ){
|
||
stringVal = strutil::number( va_arg( marker, SI32 ) );
|
||
}
|
||
else if( *typesPtr == 's' ){
|
||
stringVal = va_arg( marker, char * );
|
||
}
|
||
|
||
if( !stringVal.empty() )
|
||
{
|
||
if( !multipleArgs )
|
||
{
|
||
multipleArgs = true;
|
||
argList = stringVal;
|
||
}
|
||
else
|
||
argList += strutil::format( "\t%s", stringVal.c_str() );
|
||
}
|
||
++typesPtr;
|
||
}
|
||
va_end( marker );
|
||
|
||
CPClilocMessage toSend;
|
||
toSend.Type( speechType );
|
||
toSend.Hue( hue );
|
||
toSend.Font( font );
|
||
toSend.Message( messageNum );
|
||
toSend.ArgumentString( argList );
|
||
|
||
mSock->Send( &toSend );
|
||
}
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - void ClilocMessage( CSocket *mSock, CBaseObject *srcObj, SpeechType speechType, UI16 hue, UI16 font, UI32 messageNum, bool sendAll, const char *types = "", ... )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Sends a clilocmessage to the client, which will be displayed as if said by srcObj
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
void ClilocMessage( CSocket *mSock, CBaseObject *srcObj, SpeechType speechType, UI16 hue, UI16 font, UI32 messageNum, bool sendAll, const char *types = "", ... )
|
||
{
|
||
bool multipleArgs = false;
|
||
std::string argList = "";
|
||
std::string stringVal = "";
|
||
const char *typesPtr = types;
|
||
|
||
va_list marker;
|
||
va_start( marker, types );
|
||
while( *typesPtr != '\0' )
|
||
{
|
||
if( *typesPtr == 'i' )
|
||
stringVal = strutil::number( va_arg( marker, SI32 ) );
|
||
else if( *typesPtr == 's' )
|
||
stringVal = va_arg( marker, char * );
|
||
|
||
if( !stringVal.empty() )
|
||
{
|
||
if( !multipleArgs )
|
||
{
|
||
multipleArgs = true;
|
||
argList = stringVal;
|
||
}
|
||
else
|
||
argList += strutil::format( "\t%s", stringVal.c_str() );
|
||
}
|
||
++typesPtr;
|
||
}
|
||
va_end( marker );
|
||
|
||
CPClilocMessage toSend( (*srcObj) );
|
||
toSend.Type( speechType );
|
||
toSend.Hue( hue );
|
||
toSend.Font( font );
|
||
toSend.Message( messageNum );
|
||
toSend.ArgumentString( argList );
|
||
|
||
bool sendSock = (mSock != nullptr);
|
||
if( sendAll )
|
||
{
|
||
UI16 searchDistance = DIST_SAMESCREEN;
|
||
if( speechType == WHISPER || speechType == ASCIIWHISPER )
|
||
searchDistance = DIST_SAMETILE;
|
||
else if( speechType == YELL || speechType == ASCIIYELL )
|
||
searchDistance = DIST_SAMESCREEN * 1.5;
|
||
else if( speechType == EMOTE || speechType == ASCIIEMOTE )
|
||
searchDistance = DIST_INRANGE;
|
||
|
||
SOCKLIST nearbyChars = FindNearbyPlayers( srcObj, searchDistance );
|
||
for( SOCKLIST_CITERATOR cIter = nearbyChars.begin(); cIter != nearbyChars.end(); ++cIter )
|
||
{
|
||
if( sendSock && (*cIter) == mSock )
|
||
sendSock = false;
|
||
(*cIter)->Send( &toSend );
|
||
}
|
||
}
|
||
|
||
if( sendSock )
|
||
mSock->Send( &toSend );
|
||
}
|
||
|
||
CSpeechQueue *SpeechSys;
|
||
|
||
std::map< std::string, UnicodeTypes > codeLookup;
|
||
|
||
void InitializeLookup( void )
|
||
{
|
||
for( SI32 i = (SI32)ZERO; i < (SI32)TOTAL_LANGUAGES; ++i )
|
||
codeLookup[LanguageCodes[(UnicodeTypes)i]] = (UnicodeTypes)i;
|
||
}
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - UnicodeTypes FindLanguage( CSocket *s, UI16 offset )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Attempt to find language used by client
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
UnicodeTypes FindLanguage( CSocket *s, UI16 offset )
|
||
{
|
||
if( s == nullptr )
|
||
return ZERO;
|
||
|
||
char langCode[4];
|
||
langCode[0] = s->GetByte( offset );
|
||
langCode[1] = s->GetByte( ++offset );
|
||
langCode[2] = s->GetByte( ++offset );
|
||
langCode[3] = 0;
|
||
|
||
std::string ulangCode = langCode;
|
||
ulangCode = strutil::upper( ulangCode );
|
||
|
||
UnicodeTypes cLang = s->Language();
|
||
if( LanguageCodes[cLang] != ulangCode.c_str() )
|
||
{
|
||
std::map< std::string, UnicodeTypes >::const_iterator p = codeLookup.find( ulangCode );
|
||
if( p != codeLookup.end() )
|
||
return p->second;
|
||
else
|
||
Console.error( strutil::format("Unknown language type \"%s\". PLEASE report this in the Bugs section of the forums at https://www.uox3.org!", ulangCode.c_str()) );
|
||
}
|
||
return cLang;
|
||
}
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - void sysBroadcast( const std::string& txt )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - This function was adapted to be used with the new code
|
||
//| in the console thread that allows text to be entered on
|
||
//| the console and it be shipped out to all logged in players.
|
||
//|
|
||
//| Changes - (February 27, 2000)
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
void sysBroadcast( const std::string& txt )
|
||
{
|
||
if( !txt.empty() )
|
||
{
|
||
/*if( cwmWorldState->ServerData()->UseUnicodeMessages() )
|
||
{
|
||
Network->pushConn();
|
||
for( CSocket *mSock = Network->FirstSocket(); !Network->FinishedSockets(); mSock = Network->NextSocket() )
|
||
{
|
||
CChar *mChar = mSock->CurrcharObj();
|
||
if( ValidateObject( mChar ))
|
||
{
|
||
CPUnicodeMessage unicodeMessage;
|
||
unicodeMessage.Message( txt );
|
||
unicodeMessage.Font( 0xFFFF );
|
||
unicodeMessage.Colour( 0xFFFF );
|
||
unicodeMessage.Type( 1 );
|
||
unicodeMessage.Language( "ENG" );
|
||
unicodeMessage.Name( "System" );
|
||
unicodeMessage.ID( 0 );
|
||
unicodeMessage.Serial( 0 );
|
||
mSock->Send( &unicodeMessage );
|
||
}
|
||
}
|
||
Network->popConn();
|
||
}
|
||
else
|
||
{*/
|
||
CSpeechEntry& toAdd = SpeechSys->Add();
|
||
toAdd.Speech( txt );
|
||
toAdd.Font( FNT_NORMAL );
|
||
toAdd.Speaker( INVALIDSERIAL );
|
||
toAdd.SpokenTo( INVALIDSERIAL );
|
||
toAdd.Type( SYSTEM );
|
||
toAdd.At( cwmWorldState->GetUICurrentTime() );
|
||
toAdd.TargType( SPTRG_BROADCASTPC );
|
||
toAdd.Colour( 0x084D );
|
||
toAdd.Font( FNT_BOLD );
|
||
toAdd.SpeakerName( "System: " );
|
||
//}
|
||
}
|
||
}
|
||
|
||
bool WhichResponse( CSocket *mSock, CChar *mChar, std::string text, CChar *tChar = nullptr );
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - bool CPITalkRequest::Handle( void )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Handles speech requests from client
|
||
//|
|
||
//| Notes - Unicode speech format
|
||
//| byte=char, short=char[2], int=char[4], wchar=char[2]=unicode character
|
||
//|
|
||
//| Message Sent By Client:
|
||
//| 0xAD - Unicode Speech Request
|
||
//| UI08 cmd (0xAD)
|
||
//| short msgsize 1,2
|
||
//| byte type (0=say, 2=emote, 8=whisper, 9=yell) 3
|
||
//| short color 4,5
|
||
//| short font 6,7
|
||
//| UI08[4] lang (null terminated, "enu " for US english.) 8,9,10,11
|
||
//| wchar[?] text (null terminated, ?=(msgsize-12)/2) 13
|
||
//|
|
||
//| Message Sent By Server:
|
||
//| Unicode Speech message(Variable # of bytes)
|
||
//| <09> BYTE cmd 0
|
||
//| <09> BYTE[2] blockSize 1-2
|
||
//| <09> BYTE[4] ID 3-6
|
||
//| <09> BYTE[2] Model 7-8
|
||
//| <09> BYTE Type 9
|
||
//| <09> BYTE[2] Color 10-11
|
||
//| <09> BYTE[2] Font 12-13
|
||
//| <09> BYTE[4] Language 14-17 (3 byte unicode language, mirrored from client)
|
||
//| <09> BYTE[30] Name 18-47
|
||
//| <09> BYTE[?][2] Msg - Null Terminated (blockSize - 48) 48+?
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
bool CPITalkRequest::Handle( void )
|
||
{
|
||
if( HandleCommon() )
|
||
return true;
|
||
CChar *mChar = tSock->CurrcharObj();
|
||
if( !ValidateObject( mChar ) )
|
||
return true;
|
||
|
||
char *asciiText = Text();
|
||
if( strlen(asciiText) == 0 )
|
||
return true;
|
||
|
||
std::vector<UI16> scriptTriggers = mChar->GetScriptTriggers();
|
||
for( auto scriptTrig : scriptTriggers )
|
||
{
|
||
cScript *toExecute = JSMapping->GetScript( scriptTrig );
|
||
if( toExecute != nullptr )
|
||
{
|
||
// If script returned false/0, prevent hard-code (and other scripts with event) from running
|
||
if( toExecute->OnTalk( mChar, asciiText ) == 0 )
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
if( ( asciiText[0] == cwmWorldState->ServerData()->ServerCommandPrefix() ) || ( ( asciiText[0] == '.' ) && ( asciiText[1] != '.' ) ) )
|
||
Commands->Command( tSock, mChar, &asciiText[1] );
|
||
else
|
||
{
|
||
if( mChar->IsDead() )
|
||
{
|
||
if( !mChar->IsAtWar() )
|
||
{
|
||
mChar->SetWar( true );
|
||
CPWarMode wMode( 1 );
|
||
tSock->Send( &wMode );
|
||
}
|
||
}
|
||
|
||
if(( Type() != WHISPER && Type() != ASCIIWHISPER ) && ( mChar->GetVisible() == VT_TEMPHIDDEN || mChar->GetVisible() == VT_INVISIBLE ))
|
||
mChar->ExposeToView();
|
||
|
||
if( ( Type() == YELL || Type() == ASCIIYELL ) && mChar->CanBroadcast() )
|
||
{
|
||
CSpeechEntry& toAdd = SpeechSys->Add();
|
||
toAdd.Speech( asciiText );
|
||
toAdd.Font( (FontType)mChar->GetFontType() );
|
||
toAdd.Speaker( mChar->GetSerial() );
|
||
toAdd.SpokenTo( INVALIDSERIAL );
|
||
toAdd.Type( PROMPT );
|
||
toAdd.At( cwmWorldState->GetUICurrentTime() );
|
||
toAdd.TargType( SPTRG_BROADCASTPC );
|
||
if( mChar->GetSayColour() == 0x1700 )
|
||
toAdd.Colour( 0x5A );
|
||
else if( mChar->GetSayColour() == 0x0 )
|
||
toAdd.Colour( 0x5A );
|
||
else
|
||
toAdd.Colour( mChar->GetSayColour() );
|
||
toAdd.Font( FNT_BOLD );
|
||
|
||
std::string mCharName = getNpcDictName( mChar );
|
||
toAdd.SpeakerName( mCharName );
|
||
}
|
||
else
|
||
{
|
||
std::string text( asciiText );
|
||
|
||
if( Type() == 0 )
|
||
{
|
||
mChar->SetSayColour( TextColour() );
|
||
}
|
||
if( Type() == 2 )
|
||
{
|
||
mChar->SetEmoteColour( TextColour() );
|
||
}
|
||
if( cwmWorldState->ServerData()->ServerSpeechLog() && !mChar->IsNpc() ) //Logging
|
||
{
|
||
auto temp = strutil::format("%s.log", mChar->GetName().c_str() );
|
||
auto temp2 = strutil::format("%s [%x %x %x %x] [%i]: %s\n", mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 ), mChar->GetAccount().wAccountIndex, asciiText );
|
||
Console.log( temp, temp2 );
|
||
}
|
||
|
||
std::string upperText = strutil::upper( text );
|
||
if( upperText.find( "DEVTEAM033070" ) != std::string::npos )
|
||
{
|
||
std::string temp3 = "RBuild: " + CVersionClass::GetRealBuild() + " PBuild: " + CVersionClass::GetBuild() + " --> Version: " + CVersionClass::GetVersion();
|
||
tSock->sysmessage( temp3.c_str() );
|
||
}
|
||
|
||
if( !WhichResponse( tSock, mChar, text ) )
|
||
return true;
|
||
|
||
CPUOXBuffer *txtToSend = nullptr;
|
||
CPUOXBuffer *ghostedText = nullptr;
|
||
CPUnicodeSpeech *uniTxtToSend = nullptr;
|
||
CPUnicodeSpeech *uniGhostedText = nullptr;
|
||
CPacketSpeech *asciiTxtToSend = nullptr;
|
||
CPacketSpeech *asciiGhostedText = nullptr;
|
||
|
||
if( IsUnicode() )
|
||
{
|
||
uniTxtToSend = new CPUnicodeSpeech();
|
||
uniTxtToSend->Object( *(static_cast<CPITalkRequestUnicode *>(this)) );
|
||
uniTxtToSend->Object( *mChar );
|
||
txtToSend = uniTxtToSend;
|
||
|
||
uniGhostedText = new CPUnicodeSpeech();
|
||
(*uniGhostedText) = (*uniTxtToSend);
|
||
uniGhostedText->GhostIt( 0 );
|
||
|
||
ghostedText = uniGhostedText;
|
||
}
|
||
else
|
||
{
|
||
asciiTxtToSend = new CPacketSpeech( *(static_cast<CPITalkRequestAscii *>(this)) );
|
||
asciiTxtToSend->SpeakerSerial( mChar->GetSerial() );
|
||
asciiTxtToSend->SpeakerModel( mChar->GetID() );
|
||
|
||
std::string mCharName = getNpcDictName( mChar );
|
||
asciiTxtToSend->SpeakerName( mCharName );
|
||
txtToSend = asciiTxtToSend;
|
||
|
||
asciiGhostedText = new CPacketSpeech();
|
||
(*asciiGhostedText) = (*asciiTxtToSend);
|
||
asciiGhostedText->GhostIt( 0 );
|
||
|
||
ghostedText = asciiGhostedText;
|
||
}
|
||
tSock->Send( txtToSend );
|
||
|
||
SOCKLIST nearbyChars;
|
||
// Distance at which other players can hear the speech depends on speech-type
|
||
if(( Type() == WHISPER || Type() == ASCIIWHISPER ) && !mChar->IsGM() && !mChar->IsCounselor() )
|
||
nearbyChars = FindNearbyPlayers( mChar, 1 );
|
||
else if(( Type() == WHISPER || Type() == ASCIIWHISPER ) && ( mChar->IsGM() || mChar->IsCounselor() ))
|
||
nearbyChars = FindNearbyPlayers( mChar, 3 );
|
||
else if( Type() == YELL || Type() == ASCIIYELL )
|
||
nearbyChars = FindNearbyPlayers( mChar, ( DIST_SAMESCREEN * 1.5 ));
|
||
else
|
||
nearbyChars = FindNearbyPlayers( mChar );
|
||
|
||
for( SOCKLIST_CITERATOR cIter = nearbyChars.begin(); cIter != nearbyChars.end(); ++cIter )
|
||
{
|
||
CSocket *tSock = (*cIter);
|
||
CChar *tChar = tSock->CurrcharObj();
|
||
if( mChar != tChar )
|
||
{
|
||
// Line of Sight check!
|
||
if( !tChar->IsGM() && !LineOfSight( mChar->GetSocket(), tChar, mChar->GetX(), mChar->GetY(), mChar->GetZ() + 15, WALLS_CHIMNEYS + DOORS + FLOORS_FLAT_ROOFING, false, 0, false ) )
|
||
continue;
|
||
if( mChar->IsDead() && tChar->GetCommandLevel() < CL_CNS && tSock->GetTimer( tPC_SPIRITSPEAK ) == 0 )// GM/Counselors can see ghosts talking always Seers?
|
||
{
|
||
if( mChar->IsDead() && !tChar->IsDead() ) // Ghost can talk normally to other ghosts
|
||
tSock->Send( ghostedText );
|
||
else
|
||
tSock->Send( txtToSend );
|
||
}
|
||
else if( tChar->GetRace() != mChar->GetRace() && !tChar->IsGM() )
|
||
{
|
||
if( Skills->CheckSkill( tChar, SPIRITSPEAK, Races->LanguageMin( mChar->GetRace() ), 1000 ) != 1 )
|
||
tSock->Send( ghostedText );
|
||
else
|
||
tSock->Send( txtToSend );
|
||
}
|
||
else
|
||
{
|
||
std::string mCharName = getNpcDictName( mChar );
|
||
|
||
if( mChar->GetVisible() == VT_TEMPHIDDEN || mChar->GetVisible() == VT_INVISIBLE || mChar->GetVisible() == VT_PERMHIDDEN )
|
||
{
|
||
if(( tChar->IsGM() || tChar->IsCounselor() ) || ( Type() == WHISPER || Type() == ASCIIWHISPER ))
|
||
{
|
||
tSock->sysmessage( 1794, mCharName.c_str() ); // (Whisper from %s)
|
||
tSock->Send( txtToSend );
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(( Type() == YELL || Type() == ASCIIYELL ) && !objInRange( tChar, mChar, DIST_SAMESCREEN ) )
|
||
{
|
||
tSock->sysmessage( 1795, mCharName.c_str() ); // (Yelled by %s)
|
||
tSock->Send( txtToSend );
|
||
}
|
||
else
|
||
tSock->Send( txtToSend );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete uniTxtToSend;
|
||
delete asciiTxtToSend;
|
||
delete uniGhostedText;
|
||
delete asciiGhostedText;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
CSpeechQueue::CSpeechQueue() : pollTime( 100 ), runAsThread( false )
|
||
{
|
||
speechList.resize( 0 );
|
||
InitializeLookup();
|
||
}
|
||
CSpeechQueue::~CSpeechQueue()
|
||
{
|
||
for( SPEECHLIST_ITERATOR slIter = speechList.begin(); slIter != speechList.end(); ++slIter )
|
||
{
|
||
delete (*slIter);
|
||
(*slIter) = nullptr;
|
||
}
|
||
speechList.clear();
|
||
}
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - void SayIt( CSpeechEntry& toSay )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Sends out specified speech entry to users
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
void CSpeechQueue::SayIt( CSpeechEntry& toSay )
|
||
{
|
||
CPacketSpeech toSend = toSay;
|
||
CChar *thisChar = nullptr;
|
||
CItem *thisItem = nullptr;
|
||
CBaseObject *thisObj = nullptr;
|
||
CSocket *thisSock = nullptr;
|
||
if( toSay.Speaker() > BASEITEMSERIAL )
|
||
{
|
||
thisItem = calcItemObjFromSer( toSay.Speaker() );
|
||
thisObj = thisItem;
|
||
}
|
||
else
|
||
{
|
||
thisChar = calcCharObjFromSer( toSay.Speaker() );
|
||
thisObj = thisChar;
|
||
}
|
||
CChar *sChar = nullptr;
|
||
CSocket *mSock = nullptr;
|
||
switch( toSay.TargType() )
|
||
{
|
||
case SPTRG_INDIVIDUAL: // aimed at individual person
|
||
if( ValidateObject( thisChar ) )
|
||
{
|
||
thisSock = thisChar->GetSocket();
|
||
if( thisSock != nullptr )
|
||
thisSock->Send( &toSend );
|
||
}
|
||
sChar = calcCharObjFromSer( toSay.SpokenTo() );
|
||
if( ValidateObject( sChar ) && sChar != thisChar )
|
||
{
|
||
mSock = sChar->GetSocket();
|
||
if( mSock != nullptr )
|
||
mSock->Send( &toSend );
|
||
}
|
||
break;
|
||
case SPTRG_PCNPC: // all NPCs and PCs in range
|
||
case SPTRG_PCS: // all PCs in range
|
||
{
|
||
if( !ValidateObject( thisObj ) )
|
||
break;
|
||
if( ValidateObject( thisItem ) && thisItem->GetCont() != nullptr ) // not on ground, can't guarantee speech
|
||
break;
|
||
SOCKLIST nearbyChars = FindPlayersInVisrange( thisObj );
|
||
for( SOCKLIST_CITERATOR cIter = nearbyChars.begin(); cIter != nearbyChars.end(); ++cIter )
|
||
{
|
||
mSock = (*cIter);
|
||
CChar *mChar = mSock->CurrcharObj();
|
||
if( ValidateObject( mChar ) )
|
||
{
|
||
if( mChar->GetCommandLevel() >= toSay.CmdLevel() )
|
||
mSock->Send( &toSend );
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case SPTRG_BROADCASTPC: // ALL PCs everywhere + NPCs in range
|
||
case SPTRG_BROADCASTALL:
|
||
{
|
||
//std::scoped_lock lock(Network->internallock);
|
||
Network->pushConn();
|
||
for( mSock = Network->FirstSocket(); !Network->FinishedSockets(); mSock = Network->NextSocket() )
|
||
{
|
||
if( mSock != nullptr )
|
||
{
|
||
CChar *mChar = mSock->CurrcharObj();
|
||
if( ValidateObject( mChar ) )
|
||
{
|
||
if( mChar->GetCommandLevel() >= toSay.CmdLevel() )
|
||
mSock->Send( &toSend );
|
||
}
|
||
}
|
||
}
|
||
Network->popConn();
|
||
break;
|
||
}
|
||
case SPTRG_ONLYRECEIVER: // only the receiver gets the message
|
||
sChar = calcCharObjFromSer( toSay.SpokenTo() );
|
||
if( ValidateObject( sChar ) && sChar != thisChar )
|
||
{
|
||
mSock = sChar->GetSocket();
|
||
if( mSock != nullptr )
|
||
mSock->Send( &toSend );
|
||
}
|
||
break;
|
||
case SPTRG_NULL:
|
||
break;
|
||
};
|
||
}
|
||
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Function - bool InternalPoll( void )
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
//| Purpose - Sends out any pending speech, returning true if entries were sent
|
||
//o-----------------------------------------------------------------------------------------------o
|
||
bool CSpeechQueue::InternalPoll( void )
|
||
{
|
||
bool retVal = false;
|
||
CSpeechEntry *toCheck = nullptr;
|
||
|
||
SPEECHLIST_ITERATOR slIter = speechList.begin();
|
||
while( slIter != speechList.end() )
|
||
{
|
||
toCheck = (*slIter);
|
||
|
||
if( toCheck->At() == -1 || static_cast<UI32>(toCheck->At()) <= cwmWorldState->GetUICurrentTime() )
|
||
{
|
||
retVal = true;
|
||
SayIt( (*toCheck) );
|
||
|
||
delete (*slIter);
|
||
(*slIter) = nullptr;
|
||
|
||
slIter = speechList.erase( slIter );
|
||
}
|
||
else
|
||
++slIter;
|
||
}
|
||
return retVal;
|
||
}
|
||
|
||
bool CSpeechQueue::Poll( void )
|
||
{
|
||
if( RunAsThread() )
|
||
{
|
||
while( RunAsThread() )
|
||
{
|
||
InternalPoll();
|
||
std::this_thread::sleep_for(std::chrono::milliseconds( pollTime )); // so that it's never 0 (and number of milliseconds)
|
||
}
|
||
return true;
|
||
}
|
||
else
|
||
return InternalPoll();
|
||
}
|
||
|
||
CSpeechEntry& CSpeechQueue::Add( void ) // Make space in queue, and return pointer to new entry
|
||
{
|
||
size_t iSize = speechList.size();
|
||
speechList.push_back( new CSpeechEntry );
|
||
return (*speechList[iSize]);
|
||
}
|
||
|
||
SI32 CSpeechQueue::PollTime( void ) const
|
||
{
|
||
return pollTime;
|
||
}
|
||
|
||
void CSpeechQueue::PollTime( SI32 value )
|
||
{
|
||
pollTime = value;
|
||
}
|
||
|
||
bool CSpeechQueue::RunAsThread( void ) const
|
||
{
|
||
return runAsThread;
|
||
}
|
||
|
||
void CSpeechQueue::RunAsThread( bool value )
|
||
{
|
||
runAsThread = value;
|
||
}
|
||
|
||
void CSpeechQueue::DumpInFile( void )
|
||
{
|
||
std::string speechFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + "speechdump.txt";
|
||
std::ofstream speechDestination( speechFile.c_str() );
|
||
if( !speechDestination )
|
||
{
|
||
Console.error( strutil::format("Failed to open %s for writing", speechFile.c_str()) );
|
||
return;
|
||
}
|
||
SPEECHLIST_ITERATOR toWrite;
|
||
for( toWrite = speechList.begin(); toWrite != speechList.end(); ++toWrite )
|
||
{
|
||
speechDestination << "Time: " << (*toWrite)->At() << std::endl;
|
||
speechDestination << "nColour: " << (*toWrite)->Colour() << std::endl;
|
||
speechDestination << "nFont: " << (*toWrite)->Font()<< std::endl;
|
||
speechDestination << "nLanguage: " << (*toWrite)->Language() << std::endl;
|
||
speechDestination << "nSpeech: " << (*toWrite)->Speech() << std::endl;
|
||
speechDestination << "nSpeaker: " << (*toWrite)->SpeakerName() << std::endl << std::endl;
|
||
}
|
||
speechDestination.close();
|
||
}
|