Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the formulation of spell components will usually go something along these lines:
- // find bow->find valid arrow for the spell->check for both->pass to spell process.
- // a lot of their spells should have default component usage to make the playing
- // and spellcasting manageable. For ease of development the order objects get put in
- // the components array should be: bow->arrow->additional components.
- status spell_check_object_launch_skills(object item, int skill) {
- unless(item->is_weapon())
- return False;
- mapping skills = item->weapon()->type()->query_weapon_type_launch_skills();
- unless(skills)
- return False;
- foreach(int key, mixed val : skills) {
- if(key == skill)
- return True;
- }
- return False;
- }
- object array spell_find_bow(object who) {
- object array equipment = who->query_equipment();
- object array weapons = 0;
- object bow = 0;
- foreach(object equip : equipment) {
- if(equip->is_weapon())
- array_push_object(weapons, equip);
- }
- unless(weapons)
- return ({});
- foreach(object wep : weapons) {
- if(spell_check_object_launch_skills(wep, Skill_Archery)) {
- bow = wep;
- break;
- }
- }
- return ({ bow });
- }
- //check that they have a valid bow weapon equipped
- status spell_check_bow(object array components, object who, status initial) {
- unless(sizeof(components))
- return Error(({
- who, "must have a type of bow equipped to use this spell",
- }));
- object component = components[0];
- unless(component->is_weapon())
- return Error(({
- who, "must have a type of bow equipped to use this spell",
- }));
- status archer = False;
- if(spell_check_object_launch_skills(component, Skill_Archery))
- archer = True;
- unless(archer)
- return Error(({
- who, "must have a type of bow equipped to use this spell",
- }));
- return True;
- }
- //find their bow and any arrow, takes a status to check if their next arrow is mundane or not.
- object array spell_find_bow_and_next_arrow(object who, status mundane) {
- object array bows = spell_find_bow(who);
- unless(sizeof(bows))
- return ({});
- object bow = bows[0];
- object arrow = who->find_ammunition(bow);
- unless(arrow)
- return ({});
- if(mundane) {
- if(arrow->query_property(Prop_Magical))
- return ({});
- else
- array_push_object(bows, arrow);
- return bows;
- }
- array_push_object(bows, arrow);
- return bows;
- }
- //something we would use in spell_check_components_rule() for a valid equipped bow weapon and
- //a mundane arrow.
- status spell_check_mundane_arrow_with_bow(object array components, object who, status initial) {
- //arrow should always be 2nd object
- unless(sizeof(components) == 2)
- return Error(({
- who, "can not cast this spell without a bow equipped and an available mundane arrow.",
- }));
- object arrow = components[1];
- unless(arrow)
- return Error(({
- who, "must have a mundane arrow to cast this spell",
- }));
- if(sizeof(arrow->query_properties(Prop_Magical)))
- return Error(({
- arrow, "must be mundane to cast this spell",
- }));
- return True;
- }
- //checking if their bow has a arrow currently nocked in it or not
- status spell_check_bow_has_nocked_arrow(object who) {
- object array bows = spell_find_bow(who);
- unless(sizeof(bows))
- return False;
- object bow = bows[0];
- object array arrow_in_bow = bow->query_child_objects();
- if(sizeof(arrow_in_bow))
- return True;
- return False;
- }
- //find their next arrow or return 0
- object spell_find_any_arrow(object who) {
- object array bows = spell_find_bow(who);
- unless(sizeof(bows))
- return 0;
- object bow = bows[0];
- object arrow = who->find_ammunition(bow);
- return arrow;
- }
- //check the arrow for being mundane, for spells with only an arrow component
- varargs status spell_check_mundane_arrow(object array components, object who, status initial) {
- object arrow = components[0];
- if(sizeof(arrow->query_properties(Prop_Magical)))
- return False;
- return True;
- }
- //check if object is an arrow
- status spell_check_is_arrow(object arrow) {
- if(arrow->is_weapon()) {
- if(arrow->weapon()->type()->query_weapon_type_ammunition_type(Ammunition_Type_Bow)) {
- return True;
- }
- }
- return False;
- }
- //find a mundane arrow in either a quiver or the casters inventory or return empty array
- object array spell_find_mundane_arrow(object who) {
- object quiver = 0;
- object arrow = 0;
- //find a quiver
- foreach(object item : who->query_equipment()) {
- if(item->is_armour()) {
- if(item->armour()->query_armour_type() == Armour_Type_Quiver) {
- quiver = item;
- break;
- }
- }
- }
- Debug_To("starhound", ({ "quiver", quiver }));
- //if quiver found, check it for mundane arrows first
- if(quiver) {
- //hopefully we can assume only arrows go in quivers
- object array quiver_inv = quiver->query_child_objects();
- foreach(object arrows : quiver_inv) {
- if(spell_check_is_arrow(arrows) && spell_check_mundane_arrow(({ arrows }), who, False)) {
- arrow = arrows;
- break;
- }
- }
- }
- //if we found a mundane arrow, return it now
- Debug_To("starhound", ({ "arrow", arrow }));
- if(arrow)
- return ({ arrow });
- //if no arrow yet, check their inventory
- foreach(object item : who->query_child_objects()) {
- if(spell_check_is_arrow(item)) {
- unless(spell_check_mundane_arrow(({ item }), who, False)) {
- continue;
- } else {
- arrow = item;
- break;
- }
- }
- }
- Debug_To("starhound", arrow);
- //should return an object array with a mundane arrow, or empty array
- return array_strip_zeroes(({ arrow }));
- }
- //a function to find the object the caster is currently aiming at or default to the current attacker
- object array spell_find_aiming(object who) {
- object array bows = spell_find_bow(who);
- unless(sizeof(bows))
- return ({});
- object array attackers = ::spell_find_attacker(who);
- if(sizeof(attackers))
- return attackers;
- object bow = bows[0];
- object target = who->query_aiming(bow);
- return ({ target });
- }
- //loads an arrow into a bow, returns false if the bow already has an arrow nocked
- status spell_load_arrow_into_bow(object who, object arrow, object bow) {
- if(spell_check_bow_has_nocked_arrow(who))
- return False;
- arrow->move(bow);
- return True;
- }
- //a function to be called upon Spell_Step_Type_Gaze to make the caster aim their bow
- //outdated with the addition of Spell_Step_Type_Aim but can still be used possibly?
- void spell_start_aiming(descriptor process) {
- descriptor s_p = Process_Query_Info(process, "Spellcasting_Process");
- object array targets = Spellcasting_Process_Query(s_p, Spellcasting_Process_Targets);
- object target = targets[0];
- object who = Spellcasting_Process_Query(s_p, Spellcasting_Process_Actor);
- object array components = Spellcasting_Process_Query(s_p, Spellcasting_Process_Components);
- object bow = components[0];
- who->init_command("aim bow" + " at " + which(target, who), Command_Flag_Suppress_Activity_Checks | Command_Flag_Override);
- }
- //this function will assume there is already an arrow placed inside a bow
- //as well as aiming the bow at the target if not already aiming
- void spell_execute_bow_fire_at_target(descriptor process) {
- descriptor s_p = Process_Query_Info(process, "Spellcasting_Process");
- object array targets = Spellcasting_Process_Query(s_p, Spellcasting_Process_Targets);
- object target = targets[0];
- object who = Spellcasting_Process_Query(s_p, Spellcasting_Process_Actor);
- object array components = Spellcasting_Process_Query(s_p, Spellcasting_Process_Components);
- object bow = components[0];
- object array aim = spell_find_aiming(who);
- if(sizeof(aim)) {
- who->init_command("fire bow", Command_Flag_Override | Command_Flag_Suppress_Activity_Checks);
- } else {
- spell_start_aiming(process);
- who->init_command("fire bow", Command_Flag_Override | Command_Flag_Suppress_Activity_Checks);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement