Beispiel #1
0
    void USpell::cast( Mobile::Character* chr )
	{
	  if ( nocast_here( chr ) )
	  {
		if ( chr->client != NULL )
		  send_sysmessage( chr->client, "Spells cannot be cast here." );
		return;
	  }

	  if ( !scriptdef_.empty() )
	  {
		ref_ptr<Bscript::EScriptProgram> prog = find_script2( scriptdef_,
													 true,
													 config.cache_interactive_scripts );

		if ( prog.get() != NULL )
		{
		  if ( chr->start_spell_script( prog.get(), this ) )
			return;
		}

	  }

	  if ( chr->client != NULL )
		send_sysmessage( chr->client, "That spell doesn't seem to work." );
	}
Beispiel #2
0
void TargetCursor::handle_target_cursor( Mobile::Character* chr, PKTBI_6C* msg )
{
  if ( msg->selected_serial != 0 )   // targetted something
  {

    if ( chr->dead() )            // but is dead
    {
      if ( chr->client != NULL ) send_sysmessage( chr->client, "I am dead and cannot do that." );
      cancel( chr );
      return;
    }

    if ( ( chr->frozen() || chr->paralyzed() ) && !chr->setting_enabled( "freemove" ) )
    {
      if ( chr->client != NULL )
      {
        if ( chr->frozen() )
          private_say_above( chr, chr, "I am frozen and cannot do that." );
        else if ( chr->paralyzed() )
          private_say_above( chr, chr, "I am paralyzed and cannot do that." );
      }
      cancel( chr );
      return;
    }

    u32 selected_serial = cfBEu32( msg->selected_serial );
    UObject* obj = system_find_object( selected_serial );
    if ( obj != NULL && obj->script_isa( POLCLASS_MOBILE ) &&
         !obj->script_isa( POLCLASS_NPC ) )
    {
      Mobile::Character* targeted = find_character( selected_serial );
      // check for when char is not logged on
      if ( targeted != NULL )
      {
        if ( !chr->is_visible_to_me( targeted ) )
        {
          cancel( chr );
          return;
        }

        if ( msg->cursor_type == 1 )
        {
          if ( ( JusticeRegion::RunNoCombatCheck( chr->client ) == true )
               || ( JusticeRegion::RunNoCombatCheck( targeted->client ) == true ) )
          {
            send_sysmessage( chr->client, "Combat is not allowed in this area." );
            cancel( chr );
            return;
          }
        }
      }
    }
  }

  if ( msg->x != 0xffff || msg->selected_serial != 0 )
    on_target_cursor( chr, msg );
  else
    cancel( chr );
}
Beispiel #3
0
void NoLosCheckedTargetCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msgin )
{
  if ( msgin == NULL )
  {
    ( *func )( chr, NULL );
    return;
  }

  u32 selected_serial = cfBEu32( msgin->selected_serial );

  UObject* uobj = find_toplevel_object( selected_serial );
  // FIXME inefficient, but neither works well by itself.
  bool additlegal = false;
  if ( uobj == NULL )
    uobj = find_legal_item( chr, selected_serial, &additlegal );

  if ( uobj == NULL )
    uobj = system_find_multi( selected_serial );

  if ( uobj == NULL )
  {
    if ( chr->client != NULL ) send_sysmessage( chr->client, "What you selected does not seem to exist." );
    if ( inform_on_cancel_ )
      ( *func )( chr, NULL );
    return;
  }

  ( *func )( chr, uobj );
}
Beispiel #4
0
bool CanUseSkill(Client* client)
{
	Character* chr = client->chr;

	if ( chr->dead() )
	{
		private_say_above(chr, chr, "I am dead and cannot do that.");
		return false;
	}
	else if ( chr->skill_ex_active() || chr->casting_spell() )
	{
		private_say_above(chr, chr,"I am already performing another action.");
		return false;
	}
	else if ( poltime() < chr->disable_skills_until )
	{
		send_sysmessage(client, "You must wait to perform another action.");
		return false;
	}
	else if ( chr->frozen() || chr->paralyzed() )
	{
		private_say_above(chr, chr, "I am frozen and cannot do that.");
		return false;
	}

	return true;
}
Beispiel #5
0
bool StartSkillScript(Client *client, const Attribute* attrib)
{
	Character* chr = client->chr;
	
	ref_ptr<EScriptProgram> prog = find_script2( attrib->script_, true, // complain if not found
													config.cache_interactive_scripts );

	if ( prog.get() != NULL )
	{
		if ( chr->start_skill_script(prog.get()) )
		{
			// Should the script handle the unhiding instead?
			if ( chr->hidden() && attrib->unhides )
				chr->unhide();
			if ( attrib->delay_seconds )
			{
				chr->disable_skills_until = poltime() + attrib->delay_seconds;
			}
			return true;
		}
	}
	string msg = "Unable to start skill script:";//+attrib->script_.c_str();
	msg += attrib->script_.c_str();
	send_sysmessage(client, msg.c_str());

	return false;
}
Beispiel #6
0
void handle_use_skill(Client *client, PKTIN_12 *msg)
{
	char *params;
	unsigned int skillnum = (int)strtoul( (char *) msg->data, &params, 10);

	if ( skillnum < SKILLID__CLIENT_LOWEST || skillnum > uoclient_general.maxskills )
		return;

	const UOSkill& uoskill = GetUOSkill(skillnum);
	const Attribute* attrib = uoskill.pAttr;

	// Shouldn't most these checks be left to the scripts? - Austin
	if ( !CanUseSkill(client) )
		return;
	else if ( !attrib->script_.empty() )
	{
		if ( StartSkillScript(client, attrib) )
			return;
	}
	
	Log("Client#%lu: (%s, acct:%s) No handler for skill %d\n",
			client->instance_, client->chr->name().c_str(), client->acct->name(), int(skillnum));
	cerr << "Character " << client->chr->name() << " (acct: " << client->chr->acct->name() << "): No handler for skill " << int(skillnum) << endl;
	send_sysmessage(client, "That skill is not implemented.");
}
Beispiel #7
0
void handle_rename_char( Client* client, PKTIN_75* msg )
{
    Character* chr = find_character( cfBEu32( msg->serial ));
    if (chr != NULL)
    {
        if (client->chr->can_rename( chr ))
        {
            msg->name[ sizeof msg->name-1 ] = '\0';
            // check for legal characters
			for( char* p = msg->name; *p; p++ )
			{
				// only allow: a-z, A-Z & spaces
				if ( *p != ' ' && !isalpha(*p) )
				{
					char buffer[512];
					sprintf(buffer, "Client #%lu (account %s) attempted an invalid rename (packet 0x%2.02x):",
									client->instance_,
									(client->acct != NULL) ? client->acct->name() : "unknown",
									msg->msgtype);
					cout << buffer << endl;
					fdump( stdout, msg->name, static_cast<int>(strlen(msg->name)) );

					if (logfile)
					{
						Log("%s\n", buffer);
						fdump( logfile, msg->name, static_cast<int>(strlen(msg->name)) );
					}

					*p = '\0';
					send_sysmessage( client, "Invalid name!" );
					return; //dave 12/26 if invalid name, do not apply to chr!
				}
			}
            chr->setname( msg->name );
        }
        else
        {
            send_sysmessage( client, "I can't rename that." );
        }
    }
    else
    {
        send_sysmessage( client, "I can't find that." );
    }
}
Beispiel #8
0
void UObjectHelper::ShowProperties( Network::Client* client, PropertyList& proplist )
{
  for ( PropertyList::Properties::iterator itr = proplist.properties.begin();
        itr != proplist.properties.end(); ++itr )
  {
    OSTRINGSTREAM os;
    os << ( *itr ).first << ": " << ( *itr ).second;
    send_sysmessage( client, OSTRINGSTREAM_STR( os ) );
  }
}
Beispiel #9
0
    void handle_open_spellbook( Network::Client *client, PKTIN_12* /*msg*/ )
	{
	  if ( system_hooks.open_spellbook_hook != NULL )
	  {
		if ( system_hooks.open_spellbook_hook->call( make_mobileref( client->chr ) ) )
		  return;
	  }

	  if ( client->chr->dead() )
	  {
		send_sysmessage( client, "I am dead and cannot do that." );
		return;
	  }


	  Items::Item* spellbook = client->chr->wornitem( LAYER_HAND1 );
	  if ( spellbook == NULL )
	  {
		UContainer* backpack = client->chr->backpack();
		if ( backpack != NULL )
		{
		  spellbook = backpack->find_toplevel_polclass( POLCLASS_SPELLBOOK );

		  //
		  // Client crashes if the pack isn't open and you don't tell him
		  // about the spellbook
		  //
		  if ( spellbook != NULL )
			send_put_in_container( client, spellbook );
		}
	  }

	  if ( spellbook != NULL )
	  {
		spellbook->double_click( client );
	  }
	}
Beispiel #10
0
void equip_item( Client *client, PKTIN_13 *msg )
{
	u32 serial = cfBEu32( msg->serial );
	u8 layer = msg->layer;
	u32 equip_on_serial = cfBEu32( msg->equipped_on );

	if ((layer > HIGHEST_LAYER) || (layer == 0) || client->chr->dead())
	{
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP );
		return;
	}
	
	Item *item = client->chr->gotten_item;

	if (item == NULL)
	{
		Log( "Character %08lX tried to equip item %08lx, which did not exist in gotten_items.\n",
			 client->chr->serial, serial );
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); // 5
		return;
	}

    if (item->serial != serial)
	{
		Log( "Character %08lX tried to equip item %08lx, but had gotten item %08lX\n",
			 client->chr->serial, 
			 serial,
			 item->serial);
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); // 5
		item->gotten_by = NULL;
		return;
	}

	ItemRef itemref(item);

	item->layer = item->tile_layer;
	client->chr->gotten_item->inuse(false);
	item->is_gotten(false);
	item->gotten_by = NULL;
	client->chr->gotten_item = NULL;

    Character* equip_on = NULL;
    if (equip_on_serial == client->chr->serial)
    {
        equip_on = client->chr;
    }
    else
    {
        equip_on = find_character( equip_on_serial );
        if (equip_on == NULL ||
            !client->chr->can_clothe( equip_on ))
        {
		    send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP );

		    undo_get_item( client->chr, item );
            return;		
        }
    }

	if (equip_on->layer_is_equipped( item->tile_layer ))
	{
		// it appears the client already checks for this, so this code hasn't been exercised.
		// we'll assume client mouse holds on to object
        // 3D Client doesn't check for this!
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ALREADY_WORN );

        undo_get_item( client->chr, item ); //added 11/01/03 for 3d client
		return;
	}

    if (!equip_on->strong_enough_to_equip( item ))
    {
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP );
		// the client now puts the item back where it was before.

		// return the item to wherever it was. (?)
		undo_get_item( client->chr, item );
        if (client->chr == equip_on)
        {
            send_sysmessage( client, "You are not strong enough to use that." );
        }
        else
        {
            send_sysmessage( client, "Insufficient strength to equip that." );
        }
        return;		
    }

    if (!equip_on->equippable( item ) ||
        !item->check_equiptest_scripts( equip_on ) ||
        !item->check_equip_script( equip_on, false ))
    {
		send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP );
		if(item->orphan())
		{
			return;
		}
		undo_get_item( client->chr, item );
		return;		
    }

	if(item->orphan())
	{
		return;
	}
    
	equip_on->equip( item );
	send_wornitem_to_inrange( equip_on, item );
}
Beispiel #11
0
	void do_cast( Network::Client *client, u16 spellid )
	{
	  if ( system_hooks.on_cast_hook != NULL )
	  {
		if ( system_hooks.on_cast_hook->call( make_mobileref( client->chr ), new Bscript::BLong( spellid ) ) )
		  return;
	  }
	  // CHECKME should this look at spellnum, instead? static_cast behavior undefined if out of range.
	  if ( spellid > spells2.size() )
		return;

	  USpell *spell = spells2[spellid];
	  if ( spell == NULL )
	  {
        ERROR_PRINT << "Spell " << spellid << " is not implemented.\n";
		send_sysmessage( client, "That spell does not function." );
		return;
	  }

	  // Let scripts handle this.
	  //	if (client->chr->hidden())
	  //		client->chr->unhide();

	  if ( client->chr->frozen() )
	  {
		private_say_above( client->chr, client->chr, "I am frozen and cannot cast spells" );
		return;
	  }

	  if ( client->chr->paralyzed() )
	  {
		private_say_above( client->chr, client->chr, "I am paralyzed and cannot cast spells" );
		return;
	  }

	  if ( client->chr->skill_ex_active() )
	  {
		send_sysmessage( client, "You are already doing something else." );
		return;
	  }

	  if ( client->chr->casting_spell() )
	  {
		send_sysmessage( client, "You are already casting a spell." );
		return;
	  }

	  if ( nocast_here( client->chr ) )
	  {
		send_sysmessage( client, "Spells cannot be cast here." );
		return;
	  }

	  if ( config.require_spellbooks )
	  {
		if ( !knows_spell( client->chr, spellid ) )
		{
		  send_sysmessage( client, "You don't know that spell." );
		  return;
		}
	  }

#if 1
	  client->chr->schedule_spell( spell );
#else
	  spell->cast( client );
	  client->restart();
#endif
	}