Author Topic: Fishing  (Read 1618 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Fishing
« on: August 02, 2011, 09:26:13 PM »
Here's a revised version of the fishing ability, allowing a player or other individual to catch fish without needing a pole.

Code: [Select]
/*    /lib/fishing.c
 *    from the Dead Souls LPC Library
 *    a room which allows fishing in it
 *    created by Descartes of Borg 950529
 *    Version: @(#) fishing.c 1.7@(#)
 *    Last modified: 96/10/30
 *    T. Cook modified 2011-Aug-02 to allow pole-free fishing
 */

#include <lib.h>
#include <mouth_types.h>
#include "include/fishing.h"

inherit LIB_ROOM;

static private int MaxFishing, Speed, Chance, fishing_counter;
static private mapping Fishing, Fish;

static void create(){
room::create();
MaxFishing = 10;
Speed = 10;
Chance = 0;
fishing_counter = 0;
Fish = ([]);
Fishing = ([]);
}

void heart_beat(){
mapping tmp;
object pole;
string fisher;

room::CheckActions();

fishing_counter++;
if( fishing_counter < Speed ){ return; }
fishing_counter = 0;

if( !sizeof( Fishing ) ){ return; }
tmp = Fishing;
Fishing = ([]);
foreach( fisher, pole in tmp ){
object ob;

if( !fisher ){ continue; }
if( !( ob = present( fisher ) ) || !living( ob ) ){ continue; }
if( present( pole, ob ) && pole->GetBroken() ){ continue; }
if( (object) ob->GetInCombat() ){
message( "my_action", "You are no longer fishing.", ob );
RemoveFishing( ob );
continue;
}
if( (object) ob->GetSleeping() ){
message( "my_action", "You are no longer fishing.", ob );
RemoveFishing( ob );
continue;
}
if( pole ){ Fishing[fisher] = pole; }else{ Fishing[fisher] = ob; }
}
if( !sizeof( Fishing ) ){ return; }
foreach( fisher, pole in Fishing ){
object who;
string fish;
string blah;
int chance, x, y, i;
int pro;

who = present( fisher, this_object() );
// if this room is impossible to fish, reduce chance of fishing to 0;
if( !Chance ){ chance = 0; }
if( pole != who ){ x = pole->eventFish( who ); }
// if player has a fishing pole, increase chance of catching a fish as a bonus
if( pole != who ){
pro = ( Chance + x + who->GetStatLevel( "luck" ) ) / 3;
chance = ( Chance + x + who->GetStatLevel( "luck" ) ) / ( 1 + random( 5 ) );
}else{
pro = ( Chance + who->GetStatLevel( "luck" ) ) / 4;
chance = ( Chance + who->GetStatLevel( "luck" ) ) / ( 2 + random( 6 ) );
}
// give a bonus based on fishing skill
if( chance ){
chance += random( who->GetSkillLevel( "fishing" ) / 2 ) + 2;
}
y = 0;
foreach( fish, x in Fish ){ y += x; }
y = random( y );
if( y < 1 || chance <= random( 100 ) ){
who->eventTrainSkill( "fishing", pro, 100 - Chance / ( y + 1 ), 0 );
send_messages(
pole == who ? "try" : "cast",
"$agent_name $agent_verb again, hoping for better luck.",
who,
0,
this_object()
);
continue;
}
i = 0;
foreach( fish, x in Fish ){
i += x;
if( x >= y ){ break; }
}
who->eventTrainSkill( "fishing", pro, ( 100 - Chance ) / ( i + 1 ), 1 );
send_messages(
"struggle",
"$agent_name $agent_verb with a fish" +
( pole != who ? " on $agent_possessive " + pole->GetKeyName() : "" ) + ".",
who,
0,
this_object()
);
Fish[fish]--;
call_out( (: eventCatch, who, fish, pole :), 1 );
}
}

mixed CanCast( object who, string where ){
if( this_player()->GetInCombat() ){ return "You are too busy to fish!"; }
if( Fishing[this_player()->GetKeyName()] ){ return "You are already fishing!"; }
if( GetMaxFishing() <= sizeof( Fishing ) ){ return "It is too crowded here to fish."; }
return 1;
}

mixed CanStop( object who, string str ){
if( str != "fishing" ){ return 0; }
str = this_player()->GetKeyName();
if( !Fishing[str] ){ return "You are not fishing!"; }
return 1;
}

int CanRelease( object who ){
if( room::CanRelease() ){ RemoveFishing( who ); }
return 1;
}

varargs mixed eventCast( object who, object pole, string str ){
string catchlimb;
if( !pole ){
if( sizeof( filter( who->GetLimbs(), (: last( $1, 4 ) == "hand" :) ) ) > 0 ){
catchlimb = "hand" +
sizeof( filter( who->GetLimbs(), (: last( $1, 4 ) == "hand" :) ) ) > 1 ? "s" : "";
}else if(
sizeof( filter( who->GetLimbs(), (: last( $1, 3 ) == "paw" :) ) ) > 0 &&
!( ( who->GetMouthType() & MOUTH_NONE ) ||
( who->GetMouthType() & MOUTH_STATIC ) )
){
if( random( 100 ) < 50 ){
catchlimb = "mouth";
}else{
catchlimb = "paw" +
sizeof( filter( who->GetLimbs(), (: last( $1, 3 ) == "paw" :) ) ) > 1 ? "s" : "";
}
}else if( sizeof( filter( who->GetLimbs(), (: last( $1, 3 ) == "paw" :) ) ) > 0 ){
catchlimb = "paw" +
sizeof( filter( who->GetLimbs(), (: last( $1, 3 ) == "paw" :) ) ) > 1 ? "s" : "";
}else if(
!( ( this_player()->GetMouthType() & MOUTH_NONE ) ||
( this_player()->GetMouthType() & MOUTH_STATIC ) )
){
catchlimb = "mouth";
}else{
catchlimb = "body";
}
send_messages(
"start",
"$agent_name $agent_verb trying to catch a fish with $agent_possessive " + catchlimb + ".",
who
);
}else{
send_messages(
({ "cast", "start" }),
"$agent_name $agent_verb $agent_possessive " + pole->GetKeyName() + " and $agent_verb fishing.",
who,
0,
this_object()
);
}
SetFishing( who, pole );
return 1;
}

static void eventCatch( object who, string fish, object pole ){
object food;

if( !who || !present( who ) ){ return; }
if( pole != who && !present( pole, who ) ){
send_messages(
({ "drop", "lose" }),
"$agent_name $agent_verb " + pole->GetShort() + " and $agent_verb $agent_possessive catch!",
who
);
RemoveFishing( who );
return;
}
if( pole != who && !( pole->eventCatch( who, fish ) ) ){ return; }
food = new( fish );
RemoveFishing( who );
who->AddSkillPoints( "fishing", fish->GetFight() + fish->GetMass() );
send_messages(
"catch",
"$agent_name $agent_verb " + food->GetShort() + "!",
who
);
if( !( food->eventMove( who ) ) ){
send_messages(
"drop",
"$agent_name $agent_verb " + food->GetShort() + ", because $agent_nominative have " +
"nowhere to put it.",
who
);
food->eventMove( this_object() );
}
}

mixed eventStop( object who, string str ){
RemoveFishing( this_player() );
send_messages(
"stop",
"$agent_name $agent_verb fishing.",
who
);
return 1;
}

int SetChance( int x ){ return ( Chance = x ); }

int GetChance(){ return Chance; }

mapping SetFish( mapping mp ){ return ( Fish = mp ); }

int AddFish( string fish, int x ){
if( !Fish[fish] ){ Fish[fish] = x; }
else{ Fish[fish] += x; }
return Fish[fish];
}

mapping RemoveFish( string fish ){
if( Fish[fish] ){ map_delete( Fish, fish ); }
return Fish;
}

mapping GetFish(){ return Fish; }

varargs mapping SetFishing( object who, object pole ){
if( !living( who ) ){ return Fishing; }
if( !query_heart_beat() ){ set_heart_beat( 1 ); }
if( pole ){ Fishing[who->GetKeyName()] = pole; }else{ Fishing[who->GetKeyName()] = who; }
return Fishing;
}

mapping RemoveFishing( object who ){
string str;

if( !who || !objectp( who ) || !living( who ) ){ return Fishing; }
if( Fishing[( str = who->GetKeyName() )] ){ map_delete( Fishing, str ); }
if( !sizeof( Fishing ) ){ return ( [] ); }
return Fishing;
}

int SetMaxFishing( int x ){ return ( MaxFishing = x ); }

int GetMaxFishing(){ return MaxFishing; }

int SetSpeed( int x ){ return ( Speed = x ); }

int GetSpeed(){ return Speed; }

Code: [Select]
/*    /verbs/rooms/fish.c
 *    from the Dead Souls Mud Library
 *    fish with OBJ
 *    created by Descartes of Borg 951016
 *    T. Cook modified 2011-Aug-02 to allow 'fish' verb by itself
 */

#include <lib.h>
#include "include/fish.h"

inherit LIB_VERB;

static void create() {
    verb::create();
    SetVerb("fish");
    SetRules( "with OBJ", "" );
    SetErrorMessage("Fish with what?");
    SetHelp("Syntax: fish with <OBJ> OR fish\n\n"
            "If you have an OBJ, you will begin using it to try to catch fish, otherwise "
            "you will try to catch fish with your bare hands at a penalty.  You must be "
            "in a place that allows fishing.\n"
            "See also: stop");
}

mixed can_fish_with_obj(){
    object env;
    mixed err;
    if( !(env = environment(this_player())) ) return 0;
    err = env->CanCast(this_player());
    if( err == 1 ) return this_player()->CanManipulate();
    else if( !err ) return "It doesn't look like there is much fishing here.";
    else return err;
}

mixed do_fish_with_obj(object ob){
    object env;
    mixed err;
    if( !ob || !(env = environment(this_player())) ) return 0;
    if( err = env->eventCast(this_player(), ob) ) return err;
}

mixed can_fish(){
    object env;
    mixed err;
    if( !(env = environment(this_player())) ) return 0;
    err = env->CanCast(this_player());
    if( err == 1 ){ return 1; }
    else if( !err ) return "It doesn't look like there is much fishing here.";
    else return err;
}

mixed do_fish(){
    object env;
    mixed err;
    if( !(env = environment(this_player())) ) return 0;
    if( err = env->eventCast(this_player())  ) return err;
}