void handle_cast_spell( Network::Client *client, PKTIN_12 *msg ) { u16 spellnum = static_cast<u16>( strtoul( (char*)msg->data, NULL, 10 ) ); do_cast( client, spellnum ); }
void select_target( CHAR_DATA * ch ) { /* * Find a new target for the group to go after */ int average_level; // int tmp = 0; CHAR_DATA *vch; CHAR_DATA *victim = NULL; list<CHAR_DATA *>::iterator li; char buf[MAX_STRING_LENGTH]; int force_index = 0; bool alone = TRUE; bool mob_is_leader = FALSE; short attempts; /* * mobs were doing ethereal travel too much... i've now lowered it to * * 15% of the time and only if they are not hunting */ mob_is_leader = is_group_leader( ch ); if ( ( number_percent( ) < 15 ) && ( ch->hunting == NULL ) && ( ch->in_room->vnum != ROOM_VNUM_ETHEREAL_PLANE ) ) /* was victim == NULL, that's always true at this point.. Zen */ { if ( mob_is_leader == TRUE ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( ch, vch ) ) == TRUE ) { if ( vch->mana < mana_cost( vch, skill_lookup( "ethereal travel" ) ) ) { return; } } } } if ( ch->mana < mana_cost( ch, skill_lookup( "ethereal travel" ) ) ) return; do_say( ch, "This place is boring! I am gonna go somewhere else!" ); for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( vch, ch ) ) && ( ch != vch ) ) { do_say( vch, "Yeah, it is--we're outta here!" ); do_cast( vch, "ethereal" ); } } do_cast( ch, "ethereal" ); } else { /* * keeps checking until you've found a valid target */ attempts = 0; while ( ( victim == NULL ) && ( attempts < 15 ) ) { // ZEN FIX set average level based on level of ngroup attempts++; average_level = ch->get_level("psuedo"); force_index = number_range( 1, mob_index_list.size() ); for ( li = char_list.begin(); li != char_list.end(); li++ ) { vch = *li; if ( victim != NULL ) break; force_index--; if ( force_index > 0 ) continue; if ( valid_target( ch, vch, average_level ) ) { /* * Trick used in something else... */ if ( number_range( 0, 1 ) == 0 ) { victim = vch; } if ( victim == NULL ) /* screwed up somehow */ { continue; } if ( !IS_NPC( victim ) ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( is_same_group( ch, vch ) ) { alone = FALSE; break; } } if ( alone == FALSE ) { snprintf( buf, MSL, "%s We're coming for you!", victim->name.c_str() ); do_tell( ch, buf ); } else { snprintf( buf, MSL, "%s I'm coming for you!", victim->name.c_str() ); do_tell( ch, buf ); } } } } } if ( set_hunt( ch, NULL, victim, NULL, HUNT_WORLD | HUNT_PICKDOOR | HUNT_CR, HUNT_MERC ) ) { snprintf( buf, MSL, "Right! %s is our new target!!", victim->get_name() ); do_say( ch, buf ); } return; } return; }
void handle_msg_BF( Client* client, PKTBI_BF* msg ) { UObject* obj = NULL; UMulti* multi = NULL; UHouse* house = NULL; switch(cfBEu16(msg->subcmd)) { case PKTBI_BF::TYPE_CLIENT_LANGUAGE: client->chr->uclang = strlower(msg->client_lang); break; case PKTBI_BF::TYPE_REQ_FULL_CUSTOM_HOUSE: if( (client->UOExpansionFlag & AOS) == 0 ) return; multi = system_find_multi(cfBEu32(msg->reqfullcustomhouse.house_serial)); if(multi != NULL) { house = multi->as_house(); if(house != NULL) { if(client->UOExpansionFlag & AOS) { send_object_cache(client, (UObject*)(house)); } //consider sending working design to certain players, to assist building, or GM help CustomHousesSendFull( house, client, HOUSE_DESIGN_CURRENT ); } } break; case PKTBI_BF::TYPE_OBJECT_CACHE: if( (client->UOExpansionFlag & AOS) == 0) return; obj = system_find_object(cfBEu32(msg->objectcache.serial)); if(obj != NULL) { SendAOSTooltip(client,obj); } break; case PKTBI_BF::TYPE_SESPAM: return; break; case PKTBI_BF::TYPE_SPELL_SELECT: do_cast(client, cfBEu16(msg->spellselect.selected_spell) ); break; case PKTBI_BF::TYPE_CHARACTER_RACE_CHANGER: character_race_changer_handler( client, msg ); break; case PKTBI_BF::TYPE_PARTY_SYSTEM: party_cmd_handler( client, msg ); break; case PKTBI_BF::TYPE_EXTENDED_STATS_IN: ext_stats_in(client, msg); break; case PKTBI_BF::TYPE_CLOSED_STATUS_GUMP: return; break; case PKTBI_BF::TYPE_SCREEN_SIZE: return; break; case PKTBI_BF::TYPE_TOGGLE_FLYING: if (client->chr->race==RACE_GARGOYLE) { // FIXME: add checks if its possible to stand with new movemode client->chr->movemode = (MOVEMODE)(client->chr->movemode ^ MOVEMODE_FLY); send_move_mobile_to_nearby_cansee( client->chr ); send_goxyz( client, client->chr ); } break; case PKTBI_BF::TYPE_CLIENTTYPE: client->UOExpansionFlagClient = ctBEu32( msg->clienttype.clientflag ); break; default: handle_unknown_packet( client ); } }
void mob_is_standing( CHAR_DATA * ch ) { short dir; CHAR_DATA *vch; CHAR_DATA *tch; list<CHAR_DATA *>::iterator li; bool ready = TRUE; bool prey_still_exist = FALSE; int number_got_up = 0; int number_of_group = 1; int number_of_other_group = 1; /* * get a light source */ if ( ch->in_room->light <= 0 ) { if ( ch->mana >= mana_cost( ch, skill_lookup( "continual light" ) ) ) { do_cast( ch, "'continual light'" ); do_get( ch, "all" ); do_wear( ch, "all" ); return; } } if ( ( IS_AFFECTED( ch, AFF_POISON ) ) || ( IS_AFFECTED( ch, AFF_BLIND ) ) ) { if ( IS_AFFECTED( ch, AFF_POISON ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure poison" ) ) ) do_cast( ch, "'cure poison'" ); if ( IS_AFFECTED( ch, AFF_BLIND ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure blindness" ) ) ) do_cast( ch, "'cure blindness'" ); return; } /* * is anyone in group being attacked? if so, assist! */ /* * -leaders will be forced to rescue in the 'mob_is_fighting' function * * already so no need to check for it here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( ch, vch ) ) && ( vch->fighting != NULL ) && ( vch != ch ) ) { do_assist( ch, "" ); return; } } if ( ch->leader == NULL ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( is_same_group( ch, vch ) && ( ch != vch ) ) { number_of_group = number_of_group + 1; } } if ( number_of_group < 4 ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( vch->leader != NULL ) continue; if ( ( vch != ch ) && ( IS_NPC( vch ) ) && ( AI_MOB(vch) ) && ( !is_same_group( ch, vch ) ) && ( vch->position == POS_STANDING ) && ( ( vch->get_level("psuedo") - ch->get_level("psuedo") <= 20 && vch->get_level("psuedo") - ch->get_level("psuedo") >= -20 ) || ( ch->get_level("psuedo") - vch->get_level("psuedo") <= 20 && ch->get_level("psuedo") - vch->get_level("psuedo") >= -20 ) ) && ( can_see( vch, ch ) ) && ( can_see( ch, vch ) ) ) { if ( vch->leader == NULL ) { for ( tch = vch->in_room->first_person; tch != NULL; tch = tch->next_in_room ) { if ( is_same_group( tch, vch ) && ( tch != vch ) ) { number_of_other_group = number_of_other_group + 1; } } } if ( number_of_group + number_of_other_group <= 4 ) { get_mob_group( ch, vch ); return; } } } } } /* * do you need to heal? */ if ( ch->hit < ch->max_hit * 85 / 100 ) { if ( ( ch->mana >= mana_cost( ch, skill_lookup( "heal" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure critical" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure serious" ) ) ) ) mob_regen_check( ch, NULL, FALSE ); /* * if leader is ready to move, just keep standing */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->leader->position == POS_STANDING ) && ( ch->leader->mana >= ch->leader->max_mana * 85 / 100 ) && ( ch->leader->hit >= ch->leader->max_hit * 85 / 100 ) ) return; else { if ( ch->mana >= ch->max_mana * 75 / 100 ) ready = ready_heal_room( ch ); if ( ready == TRUE ) do_sleep( ch, "" ); return; } } if ( ch->mana < ch->max_mana * 85 / 100 ) { do_sleep( ch, "" ); return; } /* * do you need to level? if you have a group leader, have the leader * * find a the trainer. if you are the leader just go and find the * * trainer */ // ZEN FIX Have them recall then hunt the room if ( able_to_level( ch ) ) { char_from_room( ch ); char_to_room( ch, get_room_index( 3758 ) ); gain_level( ch ); return; /* dir = h_find_dir ( get_room_index(ch->in_room->vnum), get_room_index(ROOM_VNUM_INT_HEAL), ch->hunt_flags ); if ( dir == -1 ) gain_level ( ch ); else { if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) ) { hunt_move ( ch->leader, dir ); end_hunt ( ch->leader ); return; } else { hunt_move ( ch, dir ); return; } } */ } /* * if you're leader and you don't need to gain level, does anyone else * * in the group? */ /* * actually, the above function will force the leader to find a trainer * * already. but since i don't want the leader to select a new target * * until the group gains the needed level, i'll put this check here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( vch, ch ) ) && ( vch->in_room == ch->in_room ) && ( vch->leader == ch ) && ( able_to_level( vch ) ) ) { dir = h_find_dir( get_room_index( ch->in_room->vnum ), get_room_index( ROOM_VNUM_INT_HEAL ), ch->hunt_flags ); hunt_move( ch, dir ); return; } } /* * if noone needs to heal or gain level, then let's hunt! */ /* * by the way, only leaders will hunt. followers will just follow and * * assist when needed */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting != NULL ) ) { end_hunt( ch ); } else if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting == NULL ) ) { return; } else if ( is_group_leader( ch ) ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( vch != ch ) && ( is_same_group( vch, ch ) ) && ( vch->position != POS_STANDING ) ) { get_up( vch, vch->position ); number_got_up = number_got_up + 1; } } if ( number_got_up != 0 ) return; } else { if ( ch->hunting != NULL ) { for ( li = char_list.begin(); li != char_list.end(); li++ ) { vch = *li; if ( vch == ch->hunting ) { prey_still_exist = TRUE; return; } } if ( prey_still_exist == FALSE ) { ch->hunting = NULL; } } if ( ch->hunting == NULL && ch->leader == NULL ) { select_target( ch ); return; } } /* * power_up_mob ( ch ); */ /* * if ( ch->leader != NULL * && ch->in_room != ch->leader->in_room ) * { * do_follow( ch, ch->name ); * } */ return; }
static PyObject *gc_weakrefs_build(FFIObject *ffi, CDataObject *cdata, PyObject *destructor) { PyObject *new_cdata, *ref = NULL, *tup = NULL, *remove_fn = NULL; Py_ssize_t index; PyObject *datalist; if (ffi->gc_wrefs == NULL) { /* initialize */ datalist = PyList_New(0); if (datalist == NULL) return NULL; ffi->gc_wrefs = datalist; assert(ffi->gc_wrefs_freelist == NULL); ffi->gc_wrefs_freelist = Py_None; Py_INCREF(Py_None); } /* new_cdata = self.ffi.cast(typeof(cdata), cdata) */ new_cdata = do_cast(cdata->c_type, (PyObject *)cdata); if (new_cdata == NULL) goto error; /* if freelist is None: */ datalist = ffi->gc_wrefs; if (ffi->gc_wrefs_freelist == Py_None) { /* index = len(gc_wrefs) */ index = PyList_GET_SIZE(datalist); /* gc_wrefs.append(None) */ if (PyList_Append(datalist, Py_None) < 0) goto error; tup = Py_BuildValue("OOOn", ffi, destructor, cdata, index); } else { /* index = freelist */ index = PyInt_AsSsize_t(ffi->gc_wrefs_freelist); if (index < 0) goto error; /* should not occur */ tup = PyTuple_Pack(4, ffi, destructor, cdata, ffi->gc_wrefs_freelist); } if (tup == NULL) goto error; remove_fn = PyCFunction_New(&remove_callback, tup); if (remove_fn == NULL) goto error; ref = PyWeakref_NewRef(new_cdata, remove_fn); if (ref == NULL) goto error; /* freelist = gc_wrefs[index] (which is None if we just did append(None)) */ /* transfer ownership of 'datalist[index]' into gc_wrefs_freelist */ Py_DECREF(ffi->gc_wrefs_freelist); ffi->gc_wrefs_freelist = PyList_GET_ITEM(datalist, index); /* gc_wrefs[index] = ref */ /* transfer ownership of 'ref' into 'datalist[index]' */ PyList_SET_ITEM(datalist, index, ref); Py_DECREF(remove_fn); Py_DECREF(tup); return new_cdata; error: Py_XDECREF(new_cdata); Py_XDECREF(ref); Py_XDECREF(tup); Py_XDECREF(remove_fn); return NULL; }