Changeset 181

Show
Ignore:
Timestamp:
12/31/09 04:24:55 (8 months ago)
Author:
sausage
Message:

Fix flipped names in trades,
Add/fix board checks,
Fix jukebox restrictions,
Check keys for doors/chests,
Stop walking through board #8s,
Accuracy and evade twice as effective

Location:
eoserv/trunk
Files:
15 modified

Legend:

Unmodified
Added
Removed
  • eoserv/trunk/config.extra.ini

    r178 r181  
    9393JukeboxPrice = 25 
    9494 
     95## DoorTimer (number) 
     96# How long a door remains open 
     97DoorTimer = 3s 
     98 
    9599 
    96100## ITEM LIMITS ## 
  • eoserv/trunk/data/formulas.ini

    r178 r181  
    1515 
    1616# Hit rate and damage 
    17 hit_rate = 200 modifier target_evade * / 0.8 1.2 critical ? 200 accuracy / + - 0.2 max 1.0 min 
     17hit_rate = 100 modifier target_evade * / 0.8 1.0 critical ? 100 accuracy / + - 0.2 max 1.0 min 
    1818damage = 3 target_armor / modifier * damage - 0.1 damage * ceil max 1 1.5 critical ? * 
    1919 
  • eoserv/trunk/src/character.cpp

    r180 r181  
    185185        this->bank_npc = 0; 
    186186        this->barber_npc = 0; 
     187        this->board = 0; 
     188        this->jukebox_open = false; 
    187189 
    188190        this->next_arena = 0; 
     
    215217        this->party = 0; 
    216218        this->map = this->world->GetMap(0); 
    217  
    218         this->jukebox_open = false; 
    219219} 
    220220 
     
    662662        this->bank_npc = 0; 
    663663        this->barber_npc = 0; 
    664         this->jukebox_open = true; 
     664        this->board = 0; 
     665        this->jukebox_open = false; 
    665666 
    666667        this->warp_anim = animation; 
     
    781782} 
    782783 
    783 void Character::ShowBoard(int boardid) 
    784 { 
    785         if (static_cast<std::size_t>(boardid) > this->world->boards.size()) 
    786         { 
    787                 return; 
     784void Character::ShowBoard(Board *board) 
     785{ 
     786        if (!board) 
     787        { 
     788                board = this->board; 
    788789        } 
    789790 
    790791        PacketBuilder builder(PACKET_BOARD, PACKET_OPEN); 
    791         builder.AddChar(boardid); 
    792         builder.AddChar(this->world->boards[boardid]->posts.size()); 
     792        builder.AddChar(board->id + 1); 
     793        builder.AddChar(board->posts.size()); 
    793794 
    794795        int post_count = 0; 
    795796        int recent_post_count = 0; 
    796797 
    797         UTIL_PTR_LIST_FOREACH(this->world->boards[boardid]->posts, Board_Post, post) 
     798        UTIL_PTR_LIST_FOREACH(board->posts, Board_Post, post) 
    798799        { 
    799800                if (post->author == this->player->character->name) 
     
    810811        int posts_remaining = std::min(static_cast<int>(this->world->config["BoardMaxUserPosts"]) - post_count, static_cast<int>(this->world->config["BoardMaxUserRecentPosts"]) - recent_post_count); 
    811812 
    812         UTIL_PTR_LIST_FOREACH(this->world->boards[boardid]->posts, Board_Post, post) 
     813        UTIL_PTR_LIST_FOREACH(board->posts, Board_Post, post) 
    813814        { 
    814815                builder.AddShort(post->id); 
  • eoserv/trunk/src/character.hpp

    r180 r181  
    113113                NPC *bank_npc; 
    114114                NPC *barber_npc; 
     115                Board *board; 
    115116                bool jukebox_open; 
    116117 
     
    169170                void Warp(short map, unsigned char x, unsigned char y, WarpAnimation animation = WARP_ANIMATION_NONE); 
    170171                void Refresh(); 
    171                 void ShowBoard(int boardid); 
     172                void ShowBoard(Board *board = 0); 
    172173                std::string PaddedGuildTag(); 
    173174                int Usage(); 
     
    257258                SCRIPT_REGISTER_VARIABLE("NPC @", bank_npc); 
    258259                SCRIPT_REGISTER_VARIABLE("NPC @", barber_npc); 
     260                SCRIPT_REGISTER_VARIABLE("Board @", board); 
    259261                SCRIPT_REGISTER_VARIABLE("bool", jukebox_open); 
    260262                SCRIPT_REGISTER_VARIABLE("WarpAnimation", warp_anim); 
     
    293295                SCRIPT_REGISTER_FUNCTION("void Warp(int16 map, uint8 x, uint8 y, WarpAnimation animation)", Warp); 
    294296                SCRIPT_REGISTER_FUNCTION("void Refresh()", Refresh); 
    295                 SCRIPT_REGISTER_FUNCTION("void ShowBoard(int boardid)", ShowBoard); 
     297                SCRIPT_REGISTER_FUNCTION("void ShowBoard(Board @)", ShowBoard); 
    296298                SCRIPT_REGISTER_FUNCTION("string PaddedGuildTag()", PaddedGuildTag); 
    297299                SCRIPT_REGISTER_FUNCTION("int Usage()", Usage); 
  • eoserv/trunk/src/eodata.cpp

    r177 r181  
    141141} 
    142142 
     143unsigned int EIF::GetKey(int keynum) 
     144{ 
     145        int keycount = 0; 
     146 
     147        for (std::size_t i = 0; i < this->data.size(); ++i) 
     148        { 
     149                if (this->Get(i)->type == EIF::Key) 
     150                { 
     151                        if (keycount == keynum) 
     152                        { 
     153                                return i; 
     154                        } 
     155 
     156                        ++keycount; 
     157                } 
     158        } 
     159 
     160        return 0; 
     161} 
     162 
    143163void ENF::Read(std::string filename) 
    144164{ 
  • eoserv/trunk/src/eodata.hpp

    r180 r181  
    100100 
    101101                EIF_Data *Get(unsigned int id); 
     102                unsigned int GetKey(int keynum); 
    102103 
    103104        static EIF *ScriptFactory(std::string filename) { return new EIF(filename); } 
     
    166167 
    167168                SCRIPT_REGISTER_FUNCTION("EIF_Data @Get(uint)", Get); 
     169                SCRIPT_REGISTER_FUNCTION("uint GetKey(int)", GetKey); 
    168170        SCRIPT_REGISTER_END() 
    169171}; 
  • eoserv/trunk/src/handlers/Board.cpp

    r171 r181  
    66 
    77#include "handlers.h" 
     8 
     9#include "map.hpp" 
    810 
    911CLIENT_F_FUNC(Board) 
     
    1719                        if (this->state < EOClient::Playing) return false; 
    1820 
    19                         short boardid = reader.GetShort(); 
     21                        /*short boardid =*/ reader.GetShort(); 
    2022                        short postid = reader.GetShort(); 
    2123 
    22                         if (static_cast<std::size_t>(boardid) > this->server->world->boards.size()) 
     24                        if (this->player->character->board) 
    2325                        { 
    24                                 return true; 
     26                                if (this->player->character->admin < static_cast<int>(this->server->world->admin_config["boardmod"])) 
     27                                { 
     28                                        // Not in the official EO servers, but nice to use 
     29                                        this->player->character->ShowBoard(); 
     30                                        return true; 
     31                                } 
     32 
     33                                UTIL_PTR_LIST_FOREACH(this->player->character->board->posts, Board_Post, post) 
     34                                { 
     35                                        if (post->id == postid) 
     36                                        { 
     37                                                if (post->author_admin < this->player->character->admin 
     38                                                 || post->author == this->player->character->name) 
     39                                                { 
     40                                                        this->player->character->board->posts.erase(post); 
     41                                                } 
     42                                                break; 
     43                                        } 
     44                                } 
     45 
     46                                // Not in the official EO servers, but nice to use 
     47                                this->player->character->ShowBoard(); 
    2548                        } 
    26  
    27                         if (this->player->character->admin < static_cast<int>(this->server->world->admin_config["boardmod"])) 
    28                         { 
    29                                 // Not in the official EO servers, but nice to use 
    30                                 this->player->character->ShowBoard(boardid); 
    31                                 return true; 
    32                         } 
    33  
    34                         UTIL_PTR_LIST_FOREACH(this->server->world->boards[boardid]->posts, Board_Post, post) 
    35                         { 
    36                                 if (post->id == postid) 
    37                                 { 
    38                                         if (post->author_admin < this->player->character->admin 
    39                                          || post->author == this->player->character->name) 
    40                                         { 
    41                                                 this->server->world->boards[boardid]->posts.erase(post); 
    42                                         } 
    43                                         break; 
    44                                 } 
    45                         } 
    46  
    47                         // Not in the official EO servers, but nice to use 
    48                         this->player->character->ShowBoard(boardid); 
    4949                } 
    5050                break; 
     
    5454                        if (this->state < EOClient::Playing) return false; 
    5555 
    56                         short boardid = reader.GetShort(); 
     56                        /*short boardid =*/ reader.GetShort(); 
    5757                        reader.GetByte(); 
    5858                        std::string subject = reader.GetBreakString(); 
    5959                        std::string body = reader.GetBreakString(); 
    60  
    61                         if (static_cast<std::size_t>(boardid) > this->server->world->boards.size()) 
    62                         { 
    63                                 return true; 
    64                         } 
    6560 
    6661                        for (std::string::iterator i = subject.begin(); i != subject.end(); ++i) 
     
    7873                        int recent_post_count = 0; 
    7974 
    80                         UTIL_PTR_LIST_FOREACH(this->server->world->boards[boardid]->posts, Board_Post, post) 
     75                        if (this->player->character->board) 
    8176                        { 
    82                                 if (post->author == this->player->character->name) 
     77                                UTIL_PTR_LIST_FOREACH(this->player->character->board->posts, Board_Post, post) 
    8378                                { 
    84                                         ++post_count; 
     79                                        if (post->author == this->player->character->name) 
     80                                        { 
     81                                                ++post_count; 
    8582 
    86                                         if (post_count >= static_cast<int>(this->server->world->config["BoardMaxUserPosts"])) 
    87                                         { 
    88                                                 // Not in the official EO servers, but nice to use 
    89                                                 this->player->character->ShowBoard(boardid); 
    90                                                 return true; 
    91                                         } 
    92  
    93                                         if (post->time + static_cast<int>(this->server->world->config["BoardRecentPostTime"]) > Timer::GetTime()) 
    94                                         { 
    95                                                 ++recent_post_count; 
    96  
    97                                                 if (recent_post_count >= static_cast<int>(this->server->world->config["BoardMaxUserRecentPosts"])) 
     83                                                if (post_count >= static_cast<int>(this->server->world->config["BoardMaxUserPosts"])) 
    9884                                                { 
    9985                                                        // Not in the official EO servers, but nice to use 
    100                                                         this->player->character->ShowBoard(boardid); 
     86                                                        this->player->character->ShowBoard(); 
    10187                                                        return true; 
     88                                                } 
     89 
     90                                                if (post->time + static_cast<int>(this->server->world->config["BoardRecentPostTime"]) > Timer::GetTime()) 
     91                                                { 
     92                                                        ++recent_post_count; 
     93 
     94                                                        if (recent_post_count >= static_cast<int>(this->server->world->config["BoardMaxUserRecentPosts"])) 
     95                                                        { 
     96                                                                // Not in the official EO servers, but nice to use 
     97                                                                this->player->character->ShowBoard(); 
     98                                                                return true; 
     99                                                        } 
    102100                                                } 
    103101                                        } 
    104102                                } 
     103 
     104                                Board_Post *newpost = new Board_Post; 
     105                                newpost->id = ++this->player->character->board->last_id; 
     106                                newpost->author = this->player->character->name; 
     107                                newpost->author_admin = this->player->character->admin; 
     108                                newpost->subject = subject; 
     109                                newpost->body = body; 
     110                                newpost->time = Timer::GetTime(); 
     111 
     112                                this->player->character->board->posts.push_front(newpost); 
     113 
     114                                if (this->player->character->board->posts.size() > static_cast<std::size_t>(static_cast<int>(this->server->world->config["BoardMaxPosts"]))) 
     115                                { 
     116                                        this->player->character->board->posts.pop_back(); 
     117                                } 
     118 
     119                                // Not in the official EO servers, but nice to use 
     120                                this->player->character->ShowBoard(); 
    105121                        } 
    106  
    107                         Board_Post *newpost = new Board_Post; 
    108                         newpost->id = ++this->server->world->boards[boardid]->last_id; 
    109                         newpost->author = this->player->character->name; 
    110                         newpost->author_admin = this->player->character->admin; 
    111                         newpost->subject = subject; 
    112                         newpost->body = body; 
    113                         newpost->time = Timer::GetTime(); 
    114  
    115                         this->server->world->boards[boardid]->posts.push_front(newpost); 
    116  
    117                         if (this->server->world->boards[boardid]->posts.size() > static_cast<std::size_t>(static_cast<int>(this->server->world->config["BoardMaxPosts"]))) 
    118                         { 
    119                                 this->server->world->boards[boardid]->posts.pop_back(); 
    120                         } 
    121  
    122                         // Not in the official EO servers, but nice to use 
    123                         this->player->character->ShowBoard(boardid); 
    124122                } 
    125123                break; 
     
    129127                        if (this->state < EOClient::Playing) return false; 
    130128 
    131                         short boardid = reader.GetShort(); 
     129                        /*short boardid =*/ reader.GetShort(); 
    132130                        short postid = reader.GetShort(); 
    133131 
    134                         if (static_cast<std::size_t>(boardid) > this->server->world->boards.size()) 
     132                        if (this->player->character->board) 
    135133                        { 
    136                                 return true; 
    137                         } 
    138  
    139                         UTIL_PTR_LIST_FOREACH(this->server->world->boards[boardid]->posts, Board_Post, post) 
    140                         { 
    141                                 if (post->id == postid) 
     134                                UTIL_PTR_LIST_FOREACH(this->player->character->board->posts, Board_Post, post) 
    142135                                { 
    143                                         reply.SetID(PACKET_BOARD, PACKET_PLAYER); 
    144                                         reply.AddShort(postid); 
    145                                         reply.AddString(post->body); 
    146                                         CLIENT_SEND(reply); 
    147                                         break; 
     136                                        if (post->id == postid) 
     137                                        { 
     138                                                reply.SetID(PACKET_BOARD, PACKET_PLAYER); 
     139                                                reply.AddShort(postid); 
     140                                                reply.AddString(post->body); 
     141                                                CLIENT_SEND(reply); 
     142                                                break; 
     143                                        } 
    148144                                } 
    149145                        } 
     
    154150                { 
    155151                        if (this->state < EOClient::Playing) return false; 
     152                        CLIENT_QUEUE_ACTION(0.0) 
    156153 
    157154                        short boardid = reader.GetShort(); 
    158155 
    159                         this->player->character->ShowBoard(boardid); 
     156                        if (static_cast<std::size_t>(boardid) >= this->server->world->boards.size()) 
     157                        { 
     158                                return true; 
     159                        } 
     160 
     161                        for (std::size_t y = 0; y < this->player->character->map->height; ++y) 
     162                        { 
     163                                for (std::size_t x = 0; x < this->player->character->map->width; ++x) 
     164                                { 
     165                                        if (this->player->character->InRange(x, y) 
     166                                         && this->player->character->map->GetSpec(x, y) == static_cast<Map_Tile::TileSpec>(Map_Tile::Board1 + boardid)) 
     167                                        { 
     168                                                this->player->character->board = this->server->world->boards[boardid]; 
     169                                        } 
     170                                } 
     171                        } 
     172 
     173                        if (this->player->character->board) 
     174                        { 
     175                                this->player->character->ShowBoard(); 
     176                        } 
    160177                } 
    161178                break; 
  • eoserv/trunk/src/handlers/Jukebox.cpp

    r178 r181  
    1717                case PACKET_OPEN: // Opened the jukebox listing 
    1818                { 
    19                         if (this->state < EOClient::PlayingModal) return false; 
     19                        if (this->state < EOClient::Playing) return false; 
    2020                        CLIENT_QUEUE_ACTION(0.0) 
    2121 
     
    4545                case PACKET_MSG: // Requested a song 
    4646                { 
    47                         if (this->state < EOClient::PlayingModal) return false; 
     47                        if (this->state < EOClient::Playing) return false; 
    4848 
    4949                        reader.GetChar(); 
  • eoserv/trunk/src/handlers/Trade.cpp

    r171 r181  
    6060                                builder.AddBreakString(this->player->character->name); 
    6161                                CLIENT_SEND(builder); 
     62 
     63                                builder.Reset(); 
     64                                builder.AddShort(this->player->character->id); 
     65                                builder.AddBreakString(this->player->character->name); 
     66                                builder.AddShort(victim->id); 
     67                                builder.AddBreakString(victim->name); 
    6268                                victim->player->client->SendBuilder(builder); 
    6369 
  • eoserv/trunk/src/handlers/Walk.cpp

    r178 r181  
    5353                                        this->player->character->bank_npc = 0; 
    5454                                        this->player->character->barber_npc = 0; 
    55                                         this->player->character->jukebox_open = true; 
     55                                        this->player->character->board = 0; 
     56                                        this->player->character->jukebox_open = false; 
    5657                                        if (!this->player->character->Walk(direction)) 
    5758                                        { 
  • eoserv/trunk/src/main.cpp

    r179 r181  
    377377                eoserv_config_default(config, "JukeboxPrice"       , 25); 
    378378                eoserv_config_default(config, "JukeboxTimer"       , 90); 
     379                eoserv_config_default(config, "DoorTimer"          , 3.0); 
    379380                eoserv_config_default(config, "MaxBankGold"        , 2000000000); 
    380381                eoserv_config_default(config, "MaxItem"            , 10000000); 
  • eoserv/trunk/src/map.cpp

    r178 r181  
    8989                } 
    9090        } 
     91} 
     92 
     93struct map_close_door_struct : public Shared 
     94{ 
     95        Map *map; 
     96        unsigned char x, y; 
     97}; 
     98 
     99void map_close_door(void *map_close_door_struct_void) 
     100{ 
     101        map_close_door_struct *close(static_cast<map_close_door_struct *>(map_close_door_struct_void)); 
     102 
     103        close->map->CloseDoor(close->x, close->y); 
     104 
     105        close->Release(); 
    91106} 
    92107 
     
    728743        if (!admin && (warp = this->GetWarp(target_x, target_y))) 
    729744        { 
    730                 if (from->level >= warp->levelreq) 
     745                if (from->level >= warp->levelreq && (warp->spec == Map_Warp::NoDoor || warp->open)) 
    731746                { 
    732747                        from->Warp(warp->map, warp->x, warp->y); 
     
    12821297                                double hit_rate = rpn_eval(rpn_parse(this->world->formulas_config["hit_rate"]), formula_vars); 
    12831298 
    1284                                 printf("damage %i / %g > %g", amount, rand, hit_rate); 
    1285  
    12861299                                if (rand > hit_rate) 
    12871300                                { 
     
    15701583        if (Map_Warp *warp = this->GetWarp(x, y)) 
    15711584        { 
    1572                 if (warp->spec == Map_Warp::NoDoor/* || warp->open*/) 
     1585                if (warp->spec == Map_Warp::NoDoor || warp->open) 
    15731586                { 
    15741587                        return false; 
    15751588                } 
    15761589 
    1577                 // TODO: Check for keys 
    1578                 // TODO: Check for open/closed doors 
     1590                if (from && warp->spec > Map_Warp::Door) 
     1591                { 
     1592                        if (!from->HasItem(this->world->eif->GetKey(warp->spec - static_cast<int>(Map_Warp::Door)))) 
     1593                        { 
     1594                                return false; 
     1595                        } 
     1596                } 
    15791597 
    15801598                PacketBuilder builder; 
     
    15911609                } 
    15921610 
    1593                 /*warp->open = true;*/ 
     1611                warp->open = true; 
     1612 
     1613                map_close_door_struct *close = new map_close_door_struct; 
     1614                close->map = this; 
     1615                close->x = x; 
     1616                close->y = y; 
     1617 
     1618                TimeEvent *event = new TimeEvent(map_close_door, close, this->world->config["DoorTimer"], 1); // TODO: Make this a config variable 
     1619                this->world->timer.Register(event); 
     1620                event->Release(); 
     1621 
    15941622                return true; 
    15951623        } 
    15961624 
    15971625        return false; 
     1626} 
     1627 
     1628void Map::CloseDoor(unsigned char x, unsigned char y) 
     1629{ 
     1630        if (Map_Warp *warp = this->GetWarp(x, y)) 
     1631        { 
     1632                if (warp->spec == Map_Warp::NoDoor || !warp->open) 
     1633                { 
     1634                        return; 
     1635                } 
     1636 
     1637                warp->open = false; 
     1638        } 
    15981639} 
    15991640 
  • eoserv/trunk/src/map.hpp

    r175 r181  
    163163                        case Board6: 
    164164                        case Board7: 
     165                        case Board8: 
    165166                        case Jukebox: 
    166167                                return false; 
     
    339340                void Emote(Character *from, enum Emote emote, bool echo = true); 
    340341                bool OpenDoor(Character *from, unsigned char x, unsigned char y); 
     342                void CloseDoor(unsigned char x, unsigned char y); 
    341343 
    342344                bool Walk(NPC *from, Direction direction); 
     
    414416                SCRIPT_REGISTER_FUNCTION("void Emote(Character @from, Emote emote, bool echo)", Emote); 
    415417                SCRIPT_REGISTER_FUNCTION("bool OpenDoor(Character @from, uint8 x, uint8 y)", OpenDoor); 
     418                SCRIPT_REGISTER_FUNCTION("void CloseDoor(uint8 x, uint8 y)", CloseDoor); 
    416419                SCRIPT_REGISTER_FUNCTION_PR("bool Walk(NPC @from, Direction direction)", Walk, (NPC *, Direction), bool); 
    417420                SCRIPT_REGISTER_FUNCTION("Map_Item @AddItem(int16 id, int amount, uint8 x, uint8 y, Character @from)", AddItem); 
  • eoserv/trunk/src/world.cpp

    r177 r181  
    223223        for (std::size_t i = 0; i < this->boards.size(); ++i) 
    224224        { 
    225                 this->boards[i] = new Board; 
     225                this->boards[i] = new Board(i); 
    226226        } 
    227227 
  • eoserv/trunk/src/world.hpp

    r177 r181  
    3636struct Board : public Shared 
    3737{ 
     38        int id; 
    3839        short last_id; 
    3940        PtrList<Board_Post> posts; 
    4041 
    41         Board() : last_id(0) { } 
     42        Board(int id_) : id(id_), last_id(0) { } 
    4243 
    43         SCRIPT_REGISTER_REF_DF(Board) 
     44        static Board *ScriptFactory(int id) { return new Board(id); } 
     45 
     46        SCRIPT_REGISTER_REF(Board) 
     47                SCRIPT_REGISTER_FACTORY("Board @f(int id)", ScriptFactory); 
     48 
    4449                SCRIPT_REGISTER_VARIABLE("int16", last_id); 
    4550                SCRIPT_REGISTER_VARIABLE("PtrList<Board_Post>", posts);