Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
12 contributors

Users who have contributed to this file

@aleos89 @Lemongrass3110 @Atemo @cydh @secretdataz @Daegaladh @flamefury @sader1992 @Normynator @marky291 @lighta @attackjom
executable file 13236 lines (11535 sloc) 406 KB
// Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
#include "pc.hpp"
#include <map>
#include <math.h>
#include <stdlib.h>
#include <yaml-cpp/yaml.h>
#include "../common/cbasetypes.hpp"
#include "../common/core.hpp" // get_svn_revision()
#include "../common/database.hpp"
#include "../common/ers.hpp" // ers_destroy
#include "../common/malloc.hpp"
#include "../common/mmo.hpp" //NAME_LENGTH
#include "../common/nullpo.hpp"
#include "../common/random.hpp"
#include "../common/showmsg.hpp"
#include "../common/socket.hpp" // session[]
#include "../common/strlib.hpp" // safestrncpy()
#include "../common/timer.hpp"
#include "../common/utilities.hpp"
#include "../common/utils.hpp"
#include "achievement.hpp"
#include "atcommand.hpp" // get_atcommand_level()
#include "battle.hpp" // battle_config
#include "battleground.hpp"
#include "buyingstore.hpp" // struct s_buyingstore
#include "channel.hpp"
#include "chat.hpp"
#include "chrif.hpp"
#include "clan.hpp"
#include "clif.hpp"
#include "date.hpp" // is_day_of_*()
#include "duel.hpp"
#include "elemental.hpp"
#include "guild.hpp"
#include "homunculus.hpp"
#include "instance.hpp"
#include "intif.hpp"
#include "itemdb.hpp" // MAX_ITEMGROUP
#include "log.hpp"
#include "map.hpp"
#include "mercenary.hpp"
#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp" // party_search()
#include "pc_groups.hpp"
#include "pet.hpp" // pet_unlocktarget()
#include "quest.hpp"
#include "script.hpp" // struct script_reg, struct script_regstr
#include "searchstore.hpp" // struct s_search_store_info
#include "status.hpp" // OPTION_*, struct weapon_atk
#include "storage.hpp"
#include "unit.hpp" // unit_stop_attack(), unit_stop_walking()
#include "vending.hpp" // struct s_vending
using namespace rathena;
int pc_split_atoui(char* str, unsigned int* val, char sep, int max);
static inline bool pc_attendance_rewarded_today( struct map_session_data* sd );
#define PVP_CALCRANK_INTERVAL 1000 // PVP calculation interval
#define MAX_LEVEL_BASE_EXP 99999999 ///< Max Base EXP for player on Max Base Level
#define MAX_LEVEL_JOB_EXP 999999999 ///< Max Job EXP for player on Max Job Level
static unsigned int statp[MAX_LEVEL+1];
#if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
static unsigned int level_penalty[3][CLASS_MAX][MAX_LEVEL*2+1];
#endif
// h-files are for declarations, not for implementations... [Shinomori]
struct skill_tree_entry skill_tree[CLASS_COUNT][MAX_SKILL_TREE];
// timer for night.day implementation
int day_timer_tid = INVALID_TIMER;
int night_timer_tid = INVALID_TIMER;
struct eri *pc_sc_display_ers = NULL;
struct eri *num_reg_ers;
struct eri *str_reg_ers;
int pc_expiration_tid = INVALID_TIMER;
struct fame_list smith_fame_list[MAX_FAME_LIST];
struct fame_list chemist_fame_list[MAX_FAME_LIST];
struct fame_list taekwon_fame_list[MAX_FAME_LIST];
struct s_job_info job_info[CLASS_COUNT];
struct s_attendance_reward{
uint16 item_id;
uint16 amount;
};
struct s_attendance_period{
uint32 start;
uint32 end;
std::map<uint32,std::shared_ptr<struct s_attendance_reward>> rewards;
};
class AttendanceDatabase : public TypesafeYamlDatabase<uint32,s_attendance_period>{
public:
AttendanceDatabase() : TypesafeYamlDatabase( "ATTENDANCE_DB", 1 ){
}
const std::string getDefaultLocation();
uint64 parseBodyNode( const YAML::Node& node );
};
const std::string AttendanceDatabase::getDefaultLocation(){
return std::string(db_path) + "/attendance.yml";
}
/**
* Reads and parses an entry from the attendance_db.
* @param node: YAML node containing the entry.
* @return count of successfully parsed rows
*/
uint64 AttendanceDatabase::parseBodyNode(const YAML::Node &node){
uint32 start;
if( !this->asUInt32( node, "Start", start ) ){
return 0;
}
std::shared_ptr<s_attendance_period> attendance_period = this->find( start );
bool exists = attendance_period != nullptr;
if( !exists ){
if( !this->nodeExists( node, "End" ) ){
this->invalidWarning( node, "Node \"End\" is missing.\n" );
return 0;
}
if( !this->nodeExists( node, "Rewards" ) ){
this->invalidWarning( node, "Node \"Rewards\" is missing.\n" );
return 0;
}
attendance_period = std::make_shared<s_attendance_period>();
attendance_period->start = start;
}
// If it does not exist yet, we need to check it for sure
bool requiresCollisionDetection = !exists;
if( this->nodeExists( node, "End" ) ){
uint32 end;
if( !this->asUInt32( node, "End", end ) ){
return 0;
}
// If the period is outdated already, we do not even bother parsing
if( end < date_get( DT_YYYYMMDD ) ){
this->invalidWarning( node, "Node \"End\" date %u has already passed, skipping.\n", end );
return 0;
}
if( !exists || attendance_period->end != end ){
requiresCollisionDetection = true;
attendance_period->end = end;
}
}
// Collision detection
if( requiresCollisionDetection ){
bool collision = false;
for( std::pair<const uint32,std::shared_ptr<s_attendance_period>>& pair : *this ){
std::shared_ptr<s_attendance_period> period = pair.second;
if( exists && period->start == attendance_period->start ){
// Dont compare to yourself
continue;
}
// Check if start is inside another period
if( period->start <= attendance_period->start && start <= period->end ){
this->invalidWarning( node, "Node \"Start\" period %u intersects with period %u-%u, skipping.\n", attendance_period->start, period->start, period->end );
collision = true;
break;
}
// Check if end is inside another period
if( period->start <= attendance_period->end && attendance_period->end <= period->end ){
this->invalidWarning( node, "Node \"End\" period %u intersects with period %u-%u.\n", attendance_period->start, period->start, period->end );
collision = true;
break;
}
}
if( collision ){
return 0;
}
}
if( this->nodeExists( node, "Rewards" ) ){
const YAML::Node& rewardsNode = node["Rewards"];
for( const YAML::Node& rewardNode : rewardsNode ){
uint32 day;
if( !this->asUInt32( rewardNode, "Day", day ) ){
continue;
}
day -= 1;
std::shared_ptr<s_attendance_reward> reward = util::map_find( attendance_period->rewards, day );
bool reward_exists = reward != nullptr;
if( !reward_exists ){
if( !this->nodeExists( rewardNode, "ItemId" ) ){
this->invalidWarning( rewardNode, "Node \"ItemId\" is missing.\n" );
return 0;
}
reward = std::make_shared<s_attendance_reward>();
}
if( this->nodeExists( rewardNode, "ItemId" ) ){
uint16 item_id;
if( !this->asUInt16( rewardNode, "ItemId", item_id ) ){
continue;
}
if( item_id == 0 || !itemdb_exists( item_id ) ){
ShowError( "pc_attendance_load: Unknown item ID %hu for day %d.\n", item_id, day + 1 );
continue;
}
reward->item_id = item_id;
}
if( this->nodeExists( rewardNode, "Amount" ) ){
uint16 amount;
if( !this->asUInt16( rewardNode, "Amount", amount ) ){
continue;
}
if( amount == 0 ){
ShowWarning( "pc_attendance_load: Invalid reward count %hu for day %d. Defaulting to 1...\n", amount, day + 1 );
amount = 1;
}else if( amount > MAX_AMOUNT ){
ShowError( "pc_attendance_load: Reward count %hu above maximum %hu for day %d. Defaulting to %hu...\n", amount, MAX_AMOUNT, day + 1, MAX_AMOUNT );
amount = MAX_AMOUNT;
}
reward->amount = amount;
}else{
if( !reward_exists ){
reward->amount = 1;
}
}
if( !reward_exists ){
attendance_period->rewards[day] = reward;
}
}
bool missing_day = false;
for( int day = 0; day < attendance_period->rewards.size(); day++ ){
if( attendance_period->rewards.find( day ) == attendance_period->rewards.end() ){
ShowError( "pc_attendance_load: Reward for day %d is missing.\n", day + 1 );
missing_day = true;
break;
}
}
if( missing_day ){
return 0;
}
}
if( !exists ){
this->put( start, attendance_period );
}
return 1;
}
AttendanceDatabase attendance_db;
#define MOTD_LINE_SIZE 128
static char motd_text[MOTD_LINE_SIZE][CHAT_SIZE_MAX]; // Message of the day buffer [Valaris]
bool reg_load;
/**
* Translation table from athena equip index to aegis bitmask
*/
unsigned int equip_bitmask[EQI_MAX] = {
EQP_ACC_L, // EQI_ACC_L
EQP_ACC_R, // EQI_ACC_R
EQP_SHOES, // EQI_SHOES
EQP_GARMENT, // EQI_GARMENT
EQP_HEAD_LOW, // EQI_HEAD_LOW
EQP_HEAD_MID, // EQI_HEAD_MID
EQP_HEAD_TOP, // EQI_HEAD_TOP
EQP_ARMOR, // EQI_ARMOR
EQP_HAND_L, // EQI_HAND_L
EQP_HAND_R, // EQI_HAND_R
EQP_COSTUME_HEAD_TOP, // EQI_COSTUME_HEAD_TOP
EQP_COSTUME_HEAD_MID, // EQI_COSTUME_HEAD_MID
EQP_COSTUME_HEAD_LOW, // EQI_COSTUME_HEAD_LOW
EQP_COSTUME_GARMENT, // EQI_COSTUME_GARMENT
EQP_AMMO, // EQI_AMMO
EQP_SHADOW_ARMOR, // EQI_SHADOW_ARMOR
EQP_SHADOW_WEAPON, // EQI_SHADOW_WEAPON
EQP_SHADOW_SHIELD, // EQI_SHADOW_SHIELD
EQP_SHADOW_SHOES, // EQI_SHADOW_SHOES
EQP_SHADOW_ACC_R, // EQI_SHADOW_ACC_R
EQP_SHADOW_ACC_L // EQI_SHADOW_ACC_L
};
//Links related info to the sd->hate_mob[]/sd->feel_map[] entries
const struct sg_data sg_info[MAX_PC_FEELHATE] = {
{ SG_SUN_ANGER, SG_SUN_BLESS, SG_SUN_COMFORT, "PC_FEEL_SUN", "PC_HATE_MOB_SUN", is_day_of_sun },
{ SG_MOON_ANGER, SG_MOON_BLESS, SG_MOON_COMFORT, "PC_FEEL_MOON", "PC_HATE_MOB_MOON", is_day_of_moon },
{ SG_STAR_ANGER, SG_STAR_BLESS, SG_STAR_COMFORT, "PC_FEEL_STAR", "PC_HATE_MOB_STAR", is_day_of_star }
};
void pc_set_reg_load( bool val ){
reg_load = val;
}
/**
* Item Cool Down Delay Saving
* Struct item_cd is not a member of struct map_session_data
* to keep cooldowns in memory between player log-ins.
* All cooldowns are reset when server is restarted.
**/
DBMap* itemcd_db = NULL; // char_id -> struct item_cd
struct item_cd {
t_tick tick[MAX_ITEMDELAYS]; //tick
unsigned short nameid[MAX_ITEMDELAYS]; //item id
};
/**
* Converts a class to its array index for CLASS_COUNT defined arrays.
* Note that it does not do a validity check for speed purposes, where parsing
* player input make sure to use a pcdb_checkid first!
* @param class_ Job ID see enum e_job
* @return Class Index
*/
int pc_class2idx(int class_) {
if (class_ >= JOB_NOVICE_HIGH)
return class_- JOB_NOVICE_HIGH+JOB_MAX_BASIC;
return class_;
}
/**
* Get player's group ID
* @param sd
* @return Group ID
*/
int pc_get_group_id(struct map_session_data *sd) {
return sd->group_id;
}
/** Get player's group Level
* @param sd
* @return Group Level
*/
int pc_get_group_level(struct map_session_data *sd) {
return sd->group_level;
}
static TIMER_FUNC(pc_invincible_timer){
struct map_session_data *sd;
if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
return 1;
if(sd->invincible_timer != tid){
ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
return 0;
}
sd->invincible_timer = INVALID_TIMER;
skill_unit_move(&sd->bl,tick,1);
return 0;
}
void pc_setinvincibletimer(struct map_session_data* sd, int val) {
nullpo_retv(sd);
if( sd->invincible_timer != INVALID_TIMER )
delete_timer(sd->invincible_timer,pc_invincible_timer);
sd->invincible_timer = add_timer(gettick()+val,pc_invincible_timer,sd->bl.id,0);
}
void pc_delinvincibletimer(struct map_session_data* sd)
{
nullpo_retv(sd);
if( sd->invincible_timer != INVALID_TIMER )
{
delete_timer(sd->invincible_timer,pc_invincible_timer);
sd->invincible_timer = INVALID_TIMER;
skill_unit_move(&sd->bl,gettick(),1);
}
}
static TIMER_FUNC(pc_spiritball_timer){
struct map_session_data *sd;
int i;
if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
return 1;
if( sd->spiritball <= 0 )
{
ShowError("pc_spiritball_timer: %d spiritball's available. (aid=%d cid=%d tid=%d)\n", sd->spiritball, sd->status.account_id, sd->status.char_id, tid);
sd->spiritball = 0;
return 0;
}
ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == tid);
if( i == sd->spiritball )
{
ShowError("pc_spiritball_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
return 0;
}
sd->spiritball--;
if( i != sd->spiritball )
memmove(sd->spirit_timer+i, sd->spirit_timer+i+1, (sd->spiritball-i)*sizeof(int));
sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
clif_spiritball(&sd->bl);
return 0;
}
/**
* Adds a spiritball to player for 'interval' ms
* @param sd
* @param interval
* @param max
*/
void pc_addspiritball(struct map_session_data *sd,int interval,int max)
{
int tid;
uint8 i;
nullpo_retv(sd);
if(max > MAX_SPIRITBALL)
max = MAX_SPIRITBALL;
if(sd->spiritball < 0)
sd->spiritball = 0;
if( sd->spiritball && sd->spiritball >= max )
{
if(sd->spirit_timer[0] != INVALID_TIMER)
delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
sd->spiritball--;
if( sd->spiritball != 0 )
memmove(sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int));
sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
}
tid = add_timer(gettick()+interval, pc_spiritball_timer, sd->bl.id, 0);
ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == INVALID_TIMER || DIFF_TICK(get_timer(tid)->tick, get_timer(sd->spirit_timer[i])->tick) < 0);
if( i != sd->spiritball )
memmove(sd->spirit_timer+i+1, sd->spirit_timer+i, (sd->spiritball-i)*sizeof(int));
sd->spirit_timer[i] = tid;
sd->spiritball++;
if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
clif_millenniumshield(&sd->bl,sd->spiritball);
else
clif_spiritball(&sd->bl);
}
/**
* Removes number of spiritball from player
* @param sd
* @param count
* @param type 1 = doesn't give client effect
*/
void pc_delspiritball(struct map_session_data *sd,int count,int type)
{
uint8 i;
nullpo_retv(sd);
if(sd->spiritball <= 0) {
sd->spiritball = 0;
return;
}
if(count == 0)
return;
if(count > sd->spiritball)
count = sd->spiritball;
sd->spiritball -= count;
if(count > MAX_SPIRITBALL)
count = MAX_SPIRITBALL;
for(i=0;i<count;i++) {
if(sd->spirit_timer[i] != INVALID_TIMER) {
delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
sd->spirit_timer[i] = INVALID_TIMER;
}
}
for(i=count;i<MAX_SPIRITBALL;i++) {
sd->spirit_timer[i-count] = sd->spirit_timer[i];
sd->spirit_timer[i] = INVALID_TIMER;
}
if(!type) {
if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
clif_millenniumshield(&sd->bl,sd->spiritball);
else
clif_spiritball(&sd->bl);
}
}
/**
* Increases a player's fame points and displays a notice to him
* @param sd Player
* @param count Fame point
*/
void pc_addfame(struct map_session_data *sd,int count)
{
enum e_rank ranktype;
nullpo_retv(sd);
sd->status.fame += count;
if(sd->status.fame > MAX_FAME)
sd->status.fame = MAX_FAME;
switch(sd->class_&MAPID_UPPERMASK){
case MAPID_BLACKSMITH: ranktype = RANK_BLACKSMITH; break;
case MAPID_ALCHEMIST: ranktype = RANK_ALCHEMIST; break;
case MAPID_TAEKWON: ranktype = RANK_TAEKWON; break;
default:
ShowWarning( "pc_addfame: Trying to add fame to class '%s'(%d).\n", job_name(sd->class_), sd->class_ );
return;
}
clif_update_rankingpoint(sd,ranktype,count);
chrif_updatefamelist(sd);
}
/**
* Check whether a player ID is in the fame rankers list of its job, returns his/her position if so, 0 else
* @param sd
* @param job Job use enum e_mapid
* @return Rank
*/
unsigned char pc_famerank(uint32 char_id, int job)
{
uint8 i;
switch(job){
case MAPID_BLACKSMITH: // Blacksmith
for(i = 0; i < MAX_FAME_LIST; i++){
if(smith_fame_list[i].id == char_id)
return i + 1;
}
break;
case MAPID_ALCHEMIST: // Alchemist
for(i = 0; i < MAX_FAME_LIST; i++){
if(chemist_fame_list[i].id == char_id)
return i + 1;
}
break;
case MAPID_TAEKWON: // Taekwon
for(i = 0; i < MAX_FAME_LIST; i++){
if(taekwon_fame_list[i].id == char_id)
return i + 1;
}
break;
}
return 0;
}
/**
* Restart player's HP & SP value
* @param sd
* @param type Restart type: 1 - Normal Resurection
*/
void pc_setrestartvalue(struct map_session_data *sd, char type) {
struct status_data *status, *b_status;
nullpo_retv(sd);
b_status = &sd->base_status;
status = &sd->battle_status;
if (type&1) { //Normal resurrection
status->hp = 1; //Otherwise status_heal may fail if dead.
status_heal(&sd->bl, b_status->hp, 0, 1);
if( status->sp < b_status->sp )
status_set_sp(&sd->bl, b_status->sp, 1);
} else { //Just for saving on the char-server (with values as if respawned)
sd->status.hp = b_status->hp;
sd->status.sp = (status->sp < b_status->sp)?b_status->sp:status->sp;
}
}
/*==========================================
Rental System
*------------------------------------------*/
/**
* Ends a rental and removes the item/effect
* @param tid: Tick ID
* @param tick: Timer
* @param id: Timer ID
* @param data: Data
* @return false - failure, true - success
*/
TIMER_FUNC(pc_inventory_rental_end){
struct map_session_data *sd = map_id2sd(id);
if( sd == NULL )
return 0;
if( tid != sd->rental_timer ) {
ShowError("pc_inventory_rental_end: invalid timer id.\n");
return 0;
}
pc_inventory_rentals(sd);
return 1;
}
/**
* Removes the rental timer from the player
* @param sd: Player data
*/
void pc_inventory_rental_clear(struct map_session_data *sd)
{
if( sd->rental_timer != INVALID_TIMER ) {
delete_timer(sd->rental_timer, pc_inventory_rental_end);
sd->rental_timer = INVALID_TIMER;
}
}
/**
* Check for items in the player's inventory that are rental type
* @param sd: Player data
*/
void pc_inventory_rentals(struct map_session_data *sd)
{
int i, c = 0;
unsigned int next_tick = UINT_MAX;
for( i = 0; i < MAX_INVENTORY; i++ ) { // Check for Rentals on Inventory
if( sd->inventory.u.items_inventory[i].nameid == 0 )
continue; // Nothing here
if( sd->inventory.u.items_inventory[i].expire_time == 0 )
continue;
if( sd->inventory.u.items_inventory[i].expire_time <= time(NULL) ) {
if (sd->inventory_data[i]->unequip_script)
run_script(sd->inventory_data[i]->unequip_script, 0, sd->bl.id, fake_nd->bl.id);
clif_rental_expired(sd->fd, i, sd->inventory.u.items_inventory[i].nameid);
pc_delitem(sd, i, sd->inventory.u.items_inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
} else {
unsigned int expire_tick = (unsigned int)(sd->inventory.u.items_inventory[i].expire_time - time(NULL));
clif_rental_time(sd->fd, sd->inventory.u.items_inventory[i].nameid, (int)expire_tick);
next_tick = umin(expire_tick * 1000U, next_tick);
c++;
}
}
if( c > 0 ) // min(next_tick,3600000) 1 hour each timer to keep announcing to the owner, and to avoid a but with rental time > 15 days
sd->rental_timer = add_timer(gettick() + umin(next_tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
else
sd->rental_timer = INVALID_TIMER;
}
/**
* Add a rental item to the player and adjusts the rental timer appropriately
* @param sd: Player data
* @param seconds: Rental time
*/
void pc_inventory_rental_add(struct map_session_data *sd, unsigned int seconds)
{
t_tick tick = seconds * 1000;
if( sd == NULL )
return;
if( sd->rental_timer != INVALID_TIMER ) {
const struct TimerData * td;
td = get_timer(sd->rental_timer);
if( DIFF_TICK(td->tick, gettick()) > tick ) { // Update Timer as this one ends first than the current one
pc_inventory_rental_clear(sd);
sd->rental_timer = add_timer(gettick() + tick, pc_inventory_rental_end, sd->bl.id, 0);
}
} else
sd->rental_timer = add_timer(gettick() + i64min(tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
}
/**
* Check if the player can sell the current item
* @param sd: map_session_data of the player
* @param item: struct of the checking item
* @param shoptype: NPC's sub type see enum npc_subtype
* @return bool 'true' is sellable, 'false' otherwise
*/
bool pc_can_sell_item(struct map_session_data *sd, struct item *item, enum npc_subtype shoptype) {
if (sd == NULL || item == NULL)
return false;
if (item->equip > 0 || item->amount < 0)
return false;
if (battle_config.hide_fav_sell && item->favorite)
return false; //Cannot sell favs (optional config)
if (!battle_config.rental_transaction && item->expire_time)
return false; // Cannot Sell Rental Items
if( item->equipSwitch ){
return false;
}
if (itemdb_ishatched_egg(item))
return false;
switch (shoptype) {
case NPCTYPE_SHOP:
if (item->bound && battle_config.allow_bound_sell&ISR_BOUND_SELLABLE && (
item->bound != BOUND_GUILD ||
(sd->guild && sd->status.char_id == sd->guild->member[0].char_id) ||
(item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY))
))
return true;
break;
case NPCTYPE_ITEMSHOP:
if (item->bound && battle_config.allow_bound_sell&ISR_BOUND && (
item->bound != BOUND_GUILD ||
(sd->guild && sd->status.char_id == sd->guild->member[0].char_id) ||
(item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY))
))
return true;
else if (!item->bound) {
struct item_data *itd = itemdb_search(item->nameid);
if (itd && itd->flag.trade_restriction&8 && battle_config.allow_bound_sell&ISR_SELLABLE)
return true;
}
break;
}
if (!itemdb_cansell(item, pc_get_group_level(sd)))
return false;
if (item->bound && !pc_can_give_bounded_items(sd))
return false; // Don't allow sale of bound items
return true;
}
/**
* Determines if player can give / drop / trade / vend items
*/
bool pc_can_give_items(struct map_session_data *sd)
{
return pc_has_permission(sd, PC_PERM_TRADE);
}
/**
* Determines if player can give / drop / trade / vend bounded items
*/
bool pc_can_give_bounded_items(struct map_session_data *sd)
{
return pc_has_permission(sd, PC_PERM_TRADE_BOUNDED);
}
/*==========================================
* Prepares character for saving.
* @param sd
*------------------------------------------*/
void pc_makesavestatus(struct map_session_data *sd) {
nullpo_retv(sd);
if(!battle_config.save_clothcolor)
sd->status.clothes_color = 0;
// Since this is currently not officially released,
// its best to have a forced option to not save body styles.
if(!battle_config.save_body_style)
sd->status.body = 0;
//Only copy the Cart/Peco/Falcon options, the rest are handled via
//status change load/saving. [Skotlex]
#ifdef NEW_CARTS
sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
#else
sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
#endif
if (sd->sc.data[SC_JAILED]) { //When Jailed, do not move last point.
if(pc_isdead(sd)){
pc_setrestartvalue(sd, 0);
} else {
sd->status.hp = sd->battle_status.hp;
sd->status.sp = sd->battle_status.sp;
}
sd->status.last_point.map = sd->mapindex;
sd->status.last_point.x = sd->bl.x;
sd->status.last_point.y = sd->bl.y;
return;
}
if(pc_isdead(sd)) {
pc_setrestartvalue(sd, 0);
memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
} else {
sd->status.hp = sd->battle_status.hp;
sd->status.sp = sd->battle_status.sp;
sd->status.last_point.map = sd->mapindex;
sd->status.last_point.x = sd->bl.x;
sd->status.last_point.y = sd->bl.y;
}
if(map_getmapflag(sd->bl.m, MF_NOSAVE)) {
struct map_data *mapdata = map_getmapdata(sd->bl.m);
if(mapdata->save.map)
memcpy(&sd->status.last_point,&mapdata->save,sizeof(sd->status.last_point));
else
memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
}
}
/*==========================================
* Off init ? Connection?
*------------------------------------------*/
void pc_setnewpc(struct map_session_data *sd, uint32 account_id, uint32 char_id, int login_id1, t_tick client_tick, int sex, int fd) {
nullpo_retv(sd);
sd->bl.id = account_id;
sd->status.account_id = account_id;
sd->status.char_id = char_id;
sd->status.sex = sex;
sd->login_id1 = login_id1;
sd->login_id2 = 0; // at this point, we can not know the value :(
sd->client_tick = client_tick;
sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
sd->bl.type = BL_PC;
if(battle_config.prevent_logout_trigger&PLT_LOGIN)
sd->canlog_tick = gettick();
//Required to prevent homunculus copuing a base speed of 0.
sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
}
/**
* Get equip point for an equip
* @param sd
* @param id
*/
int pc_equippoint_sub(struct map_session_data *sd,struct item_data* id){
int ep = 0;
nullpo_ret(sd);
nullpo_ret(id);
if (!itemdb_isequip2(id))
return 0; //Not equippable by players.
ep = id->equip;
if(id->look == W_DAGGER || id->look == W_1HSWORD || id->look == W_1HAXE) {
if(pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN || (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO) { //Kagerou and Oboro can dual wield daggers. [Rytech]
if (ep == EQP_WEAPON)
return EQP_ARMS;
if (ep == EQP_SHADOW_WEAPON)
return EQP_SHADOW_ARMS;
}
}
return ep;
}
/**
* Get equip point for an equip
* @param sd
* @param n Equip index in inventory
*/
int pc_equippoint(struct map_session_data *sd,int n){
nullpo_ret(sd);
return pc_equippoint_sub(sd,sd->inventory_data[n]);
}
/**
* Fill inventory_data with struct *item_data through inventory (fill with struct *item)
* @param sd : player session
* @return 0 sucess, 1:invalid sd
*/
void pc_setinventorydata(struct map_session_data *sd)
{
uint8 i;
nullpo_retv(sd);
for(i = 0; i < MAX_INVENTORY; i++) {
unsigned short id = sd->inventory.u.items_inventory[i].nameid;
sd->inventory_data[i] = id?itemdb_search(id):NULL;
}
}
/**
* 'Calculates' weapon type
* @param sd : Player
*/
void pc_calcweapontype(struct map_session_data *sd)
{
nullpo_retv(sd);
// single-hand
if(sd->weapontype2 == W_FIST) {
sd->status.weapon = sd->weapontype1;
return;
}
if(sd->weapontype1 == W_FIST) {
sd->status.weapon = sd->weapontype2;
return;
}
// dual-wield
sd->status.weapon = 0;
switch (sd->weapontype1){
case W_DAGGER:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
}
break;
case W_1HSWORD:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
}
break;
case W_1HAXE:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
}
}
// unknown, default to right hand type
if (!sd->status.weapon)
sd->status.weapon = sd->weapontype1;
}
/**
* Set equip index
* @param sd : Player
*/
void pc_setequipindex(struct map_session_data *sd)
{
uint16 i;
nullpo_retv(sd);
for (i = 0; i < EQI_MAX; i++){
sd->equip_index[i] = -1;
sd->equip_switch_index[i] = -1;
}
for (i = 0; i < MAX_INVENTORY; i++) {
if (sd->inventory.u.items_inventory[i].nameid <= 0)
continue;
if (sd->inventory.u.items_inventory[i].equip) {
uint8 j;
for (j = 0; j < EQI_MAX; j++)
if (sd->inventory.u.items_inventory[i].equip & equip_bitmask[j])
sd->equip_index[j] = i;
if (sd->inventory.u.items_inventory[i].equip & EQP_HAND_R) {
if (sd->inventory_data[i])
sd->weapontype1 = sd->inventory_data[i]->look;
else
sd->weapontype1 = 0;
}
if( sd->inventory.u.items_inventory[i].equip & EQP_HAND_L ) {
if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
sd->weapontype2 = sd->inventory_data[i]->look;
else
sd->weapontype2 = 0;
}
}
if (sd->inventory.u.items_inventory[i].equipSwitch) {
for (uint8 j = 0; j < EQI_MAX; j++) {
if (sd->inventory.u.items_inventory[i].equipSwitch & equip_bitmask[j]) {
sd->equip_switch_index[j] = i;
}
}
}
}
pc_calcweapontype(sd);
}
//static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
//{
// int i;
// struct item *item = &sd->inventory.u.items_inventory[eqindex];
// struct item_data *data;
//
// //Crafted/made/hatched items.
// if (itemdb_isspecial(item->card[0]))
// return 1;
//
// /* scan for enchant armor gems */
// if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 )
// s = MAX_SLOTS - 1;
//
// ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
// return( i < s ) ? 0 : 1;
//}
/**
* Check if an item is equiped by player
* (Check if the itemid is equiped then search if that match the index in inventory (should be))
* @param sd : player session
* @param nameid : itemid
* @return 1:yes, 0:no
*/
bool pc_isequipped(struct map_session_data *sd, unsigned short nameid)
{
uint8 i;
for( i = 0; i < EQI_MAX; i++ )
{
short index = sd->equip_index[i], j;
if( index < 0 )
continue;
if( pc_is_same_equip_index((enum equip_index)i, sd->equip_index, index) )
continue;
if( !sd->inventory_data[index] )
continue;
if( sd->inventory_data[index]->nameid == nameid )
return true;
for( j = 0; j < sd->inventory_data[index]->slot; j++ ){
if( sd->inventory.u.items_inventory[index].card[j] == nameid )
return true;
}
}
return false;
}
/**
* Check adoption rules
* @param p1_sd: Player 1
* @param p2_sd: Player 2
* @param b_sd: Player that will be adopted
* @return ADOPT_ALLOWED - Sent message to Baby to accept or deny
* ADOPT_ALREADY_ADOPTED - Already adopted
* ADOPT_MARRIED_AND_PARTY - Need to be married and in the same party
* ADOPT_EQUIP_RINGS - Need wedding rings equipped
* ADOPT_NOT_NOVICE - Adoptee is not a Novice
* ADOPT_CHARACTER_NOT_FOUND - Parent or Baby not found
* ADOPT_MORE_CHILDREN - Cannot adopt more than 1 Baby (client message)
* ADOPT_LEVEL_70 - Parents need to be level 70+ (client message)
* ADOPT_MARRIED - Cannot adopt a married person (client message)
*/
enum adopt_responses pc_try_adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
{
if( !p1_sd || !p2_sd || !b_sd )
return ADOPT_CHARACTER_NOT_FOUND;
if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
return ADOPT_ALREADY_ADOPTED; // already adopted baby / in adopt request
if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
return ADOPT_MARRIED_AND_PARTY; // You need to be married and in party with baby to adopt
if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
return ADOPT_MARRIED_AND_PARTY; // Not married, wrong married
if( p2_sd->status.party_id != p1_sd->status.party_id )
return ADOPT_MARRIED_AND_PARTY; // Both parents need to be in the same party
// Parents need to have their ring equipped
if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
return ADOPT_EQUIP_RINGS;
if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
return ADOPT_EQUIP_RINGS;
// Already adopted a baby
if( p1_sd->status.child || p2_sd->status.child ) {
clif_Adopt_reply(p1_sd, ADOPT_REPLY_MORE_CHILDREN);
return ADOPT_MORE_CHILDREN;
}
// Parents need at least lvl 70 to adopt
if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
clif_Adopt_reply(p1_sd, ADOPT_REPLY_LEVEL_70);
return ADOPT_LEVEL_70;
}
if( b_sd->status.partner_id ) {
clif_Adopt_reply(p1_sd, ADOPT_REPLY_MARRIED);
return ADOPT_MARRIED;
}
if( !( ( b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF ) || b_sd->status.class_ == JOB_SUPER_NOVICE || b_sd->status.class_ == JOB_SUPER_NOVICE_E ) )
return ADOPT_NOT_NOVICE;
return ADOPT_ALLOWED;
}
/*==========================================
* Adoption Process
*------------------------------------------*/
bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
{
int job, joblevel;
unsigned int jobexp;
if( pc_try_adopt(p1_sd, p2_sd, b_sd) != ADOPT_ALLOWED )
return false;
// Preserve current job levels and progress
joblevel = b_sd->status.job_level;
jobexp = b_sd->status.job_exp;
job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
if( job != -1 && pc_jobchange(b_sd, job, 0) )
{ // Success, proceed to configure parents and baby skills
p1_sd->status.child = b_sd->status.char_id;
p2_sd->status.child = b_sd->status.char_id;
b_sd->status.father = p1_sd->status.char_id;
b_sd->status.mother = p2_sd->status.char_id;
// Restore progress
b_sd->status.job_level = joblevel;
clif_updatestatus(b_sd, SP_JOBLEVEL);
b_sd->status.job_exp = jobexp;
clif_updatestatus(b_sd, SP_JOBEXP);
// Baby Skills
pc_skill(b_sd, WE_BABY, 1, ADDSKILL_PERMANENT);
pc_skill(b_sd, WE_CALLPARENT, 1, ADDSKILL_PERMANENT);
pc_skill(b_sd, WE_CHEERUP, 1, ADDSKILL_PERMANENT);
// Parents Skills
pc_skill(p1_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
pc_skill(p2_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
chrif_save(p1_sd, CSAVE_NORMAL);
chrif_save(p2_sd, CSAVE_NORMAL);
chrif_save(b_sd, CSAVE_NORMAL);
achievement_update_objective(b_sd, AG_BABY, 1, 1);
achievement_update_objective(p1_sd, AG_BABY, 1, 2);
achievement_update_objective(p2_sd, AG_BABY, 1, 2);
return true;
}
return false; // Job Change Fail
}
/*==========================================
* Check if player can use/equip selected item. Used by pc_isUseitem and pc_isequip
Returns:
false : Cannot use/equip
true : Can use/equip
* Credits:
[Inkfish] for first idea
[Haru] for third-classes extension
[Cydh] finishing :D
*------------------------------------------*/
static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) {
while (1) {
if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third)
break;
#ifndef RENEWAL
//allow third classes to use trans. class items
if (item->class_upper&ITEMJ_UPPER && sd->class_&(JOBL_UPPER|JOBL_THIRD)) //trans. classes
break;
//third-baby classes can use same item too
if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY) //baby classes
break;
//don't need to decide specific rules for third-classes?
//items for third classes can be used for all third classes
if (item->class_upper&(ITEMJ_THIRD|ITEMJ_THIRD_TRANS|ITEMJ_THIRD_BABY) && sd->class_&JOBL_THIRD)
break;
#else
//trans. classes (exl. third-trans.)
if (item->class_upper&ITEMJ_UPPER && sd->class_&JOBL_UPPER && !(sd->class_&JOBL_THIRD))
break;
//baby classes (exl. third-baby)
if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY && !(sd->class_&JOBL_THIRD))
break;
//third classes (exl. third-trans. and baby-third)
if (item->class_upper&ITEMJ_THIRD && sd->class_&JOBL_THIRD && !(sd->class_&(JOBL_UPPER|JOBL_BABY)))
break;
//trans-third classes
if (item->class_upper&ITEMJ_THIRD_TRANS && sd->class_&JOBL_THIRD && sd->class_&JOBL_UPPER)
break;
//third-baby classes
if (item->class_upper&ITEMJ_THIRD_BABY && sd->class_&JOBL_THIRD && sd->class_&JOBL_BABY)
break;
#endif
return false;
}
return true;
}
/*=================================================
* Checks if the player can equip the item at index n in inventory.
* @param sd
* @param n Item index in inventory
* @return ITEM_EQUIP_ACK_OK(0) if can be equipped, or ITEM_EQUIP_ACK_FAIL(1)/ITEM_EQUIP_ACK_FAILLEVEL(2) if can't
*------------------------------------------------*/
uint8 pc_isequip(struct map_session_data *sd,int n)
{
struct item_data *item;
nullpo_retr(ITEM_EQUIP_ACK_FAIL, sd);
item = sd->inventory_data[n];
if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
return ITEM_EQUIP_ACK_OK;
if(item == NULL)
return ITEM_EQUIP_ACK_FAIL;
if(item->elv && sd->status.base_level < (unsigned int)item->elv)
return ITEM_EQUIP_ACK_FAILLEVEL;
if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
return ITEM_EQUIP_ACK_FAILLEVEL;
if(item->sex != 2 && sd->status.sex != item->sex)
return ITEM_EQUIP_ACK_FAIL;
//fail to equip if item is restricted
if (!battle_config.allow_equip_restricted_item && itemdb_isNoEquip(item, sd->bl.m))
return ITEM_EQUIP_ACK_FAIL;
if (item->equip&EQP_AMMO) {
switch (item->look) {
case AMMO_ARROW:
if (battle_config.ammo_check_weapon && sd->status.weapon != W_BOW && sd->status.weapon != W_MUSICAL && sd->status.weapon != W_WHIP) {
clif_msg(sd, ITEM_NEED_BOW);
return ITEM_EQUIP_ACK_FAIL;
}
break;
case AMMO_THROWABLE_DAGGER:
if (!pc_checkskill(sd, AS_VENOMKNIFE))
return ITEM_EQUIP_ACK_FAIL;
break;
case AMMO_BULLET:
case AMMO_SHELL:
if (battle_config.ammo_check_weapon && sd->status.weapon != W_REVOLVER && sd->status.weapon != W_RIFLE && sd->status.weapon != W_GATLING && sd->status.weapon != W_SHOTGUN
#ifdef RENEWAL
&& sd->status.weapon != W_GRENADE
#endif
) {
clif_msg(sd, ITEM_BULLET_EQUIP_FAIL);
return ITEM_EQUIP_ACK_FAIL;
}
break;
#ifndef RENEWAL
case AMMO_GRENADE:
if (battle_config.ammo_check_weapon && sd->status.weapon != W_GRENADE) {
clif_msg(sd, ITEM_BULLET_EQUIP_FAIL);
return ITEM_EQUIP_ACK_FAIL;
}
break;
#endif
case AMMO_CANNONBALL:
if (!pc_ismadogear(sd) && (sd->status.class_ == JOB_MECHANIC_T || sd->status.class_ == JOB_MECHANIC)) {
clif_msg(sd, ITEM_NEED_MADOGEAR); // Item can only be used when Mado Gear is mounted.
return ITEM_EQUIP_ACK_FAIL;
}
if (sd->state.active && !pc_iscarton(sd) && //Check if sc data is already loaded
(sd->status.class_ == JOB_GENETIC_T || sd->status.class_ == JOB_GENETIC)) {
clif_msg(sd, ITEM_NEED_CART); // Only available when cart is mounted.
return ITEM_EQUIP_ACK_FAIL;
}
break;
}
}
if (sd->sc.count) {
if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
return ITEM_EQUIP_ACK_FAIL;
if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
return ITEM_EQUIP_ACK_FAIL;
if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
return ITEM_EQUIP_ACK_FAIL;
if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_STRIPHELM])
return ITEM_EQUIP_ACK_FAIL;
if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSORY])
return ITEM_EQUIP_ACK_FAIL;
if (item->equip & EQP_ARMS && sd->sc.data[SC__WEAKNESS])
return ITEM_EQUIP_ACK_FAIL;
if(item->equip && (sd->sc.data[SC_KYOUGAKU] || sd->sc.data[SC_SUHIDE]))
return ITEM_EQUIP_ACK_FAIL;
if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
//Spirit of Super Novice equip bonuses. [Skotlex]
if (sd->status.base_level > 90 && item->equip & EQP_HELM)
return ITEM_EQUIP_ACK_OK; //Can equip all helms
if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON && item->wlv == 4)
switch(item->look) { //In weapons, the look determines type of weapon.
case W_DAGGER: //All level 4 - Daggers
case W_1HSWORD: //All level 4 - 1H Swords
case W_1HAXE: //All level 4 - 1H Axes
case W_MACE: //All level 4 - 1H Maces
case W_STAFF: //All level 4 - 1H Staves
case W_2HSTAFF: //All level 4 - 2H Staves
return ITEM_EQUIP_ACK_OK;
}
}
}
//Not equipable by class. [Skotlex]
if (!(1ULL << (sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1) ? 1 : ((sd->class_&JOBL_2_2) ? 2 : 0)]))
return ITEM_EQUIP_ACK_FAIL;
if (!pc_isItemClass(sd, item))
return ITEM_EQUIP_ACK_FAIL;
return ITEM_EQUIP_ACK_OK;
}
/*==========================================
* No problem with the session id
* set the status that has been sent from char server
*------------------------------------------*/
bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers)
{
int i;
t_tick tick = gettick();
uint32 ip = session[sd->fd]->client_addr;
sd->login_id2 = login_id2;
sd->group_id = group_id;
/* load user permissions */
pc_group_pc_load(sd);
memcpy(&sd->status, st, sizeof(*st));
if (st->sex != sd->status.sex) {
clif_authfail_fd(sd->fd, 0);
return false;
}
//Set the map-server used job id. [Skotlex]
i = pc_jobid2mapid(sd->status.class_);
if (i == -1) { //Invalid class?
ShowError("pc_authok: Invalid class %d for player %s (%d:%d). Class was changed to novice.\n", sd->status.class_, sd->status.name, sd->status.account_id, sd->status.char_id);
sd->status.class_ = JOB_NOVICE;
sd->class_ = MAPID_NOVICE;
} else
sd->class_ = i;
// Checks and fixes to character status data, that are required
// in case of configuration change or stuff, which cannot be
// checked on char-server.
sd->status.hair = cap_value(sd->status.hair,MIN_HAIR_STYLE,MAX_HAIR_STYLE);
sd->status.hair_color = cap_value(sd->status.hair_color,MIN_HAIR_COLOR,MAX_HAIR_COLOR);
sd->status.clothes_color = cap_value(sd->status.clothes_color,MIN_CLOTH_COLOR,MAX_CLOTH_COLOR);
sd->status.body = cap_value(sd->status.body,MIN_BODY_STYLE,MAX_BODY_STYLE);
//Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
sd->state.connect_new = 1;
sd->followtimer = INVALID_TIMER; // [MouseJstr]
sd->invincible_timer = INVALID_TIMER;
sd->npc_timer_id = INVALID_TIMER;
sd->pvp_timer = INVALID_TIMER;
sd->expiration_tid = INVALID_TIMER;
sd->autotrade_tid = INVALID_TIMER;
#ifdef SECURE_NPCTIMEOUT
// Initialize to defaults/expected
sd->npc_idle_timer = INVALID_TIMER;
sd->npc_idle_tick = tick;
sd->npc_idle_type = NPCT_INPUT;
sd->state.ignoretimeout = false;
#endif
sd->canuseitem_tick = tick;
sd->canusecashfood_tick = tick;
sd->canequip_tick = tick;
sd->cantalk_tick = tick;
sd->canskill_tick = tick;
sd->cansendmail_tick = tick;
sd->idletime = last_tick;
for(i = 0; i < MAX_SPIRITBALL; i++)
sd->spirit_timer[i] = INVALID_TIMER;
if (battle_config.item_auto_get)
sd->state.autoloot = 10000;
if (battle_config.disp_experience)
sd->state.showexp = 1;
if (battle_config.disp_zeny)
sd->state.showzeny = 1;
#ifdef VIP_ENABLE
if (!battle_config.vip_disp_rate)
sd->vip.disableshowrate = 1;
#endif
if (!(battle_config.display_skill_fail&2))
sd->state.showdelay = 1;
memset(&sd->inventory, 0, sizeof(struct s_storage));
memset(&sd->cart, 0, sizeof(struct s_storage));
memset(&sd->storage, 0, sizeof(struct s_storage));
memset(&sd->premiumStorage, 0, sizeof(struct s_storage));
memset(&sd->equip_index, -1, sizeof(sd->equip_index));
memset(&sd->equip_switch_index, -1, sizeof(sd->equip_switch_index));
if( pc_isinvisible(sd) && !pc_can_use_command( sd, "hide", COMMAND_ATCOMMAND ) ){
sd->status.option &= ~OPTION_INVISIBLE;
}
status_change_init(&sd->bl);
sd->sc.option = sd->status.option; //This is the actual option used in battle.
unit_dataset(&sd->bl);
sd->guild_x = -1;
sd->guild_y = -1;
sd->delayed_damage = 0;
// Event Timers
for( i = 0; i < MAX_EVENTTIMER; i++ )
sd->eventtimer[i] = INVALID_TIMER;
// Rental Timer
sd->rental_timer = INVALID_TIMER;
for( i = 0; i < 3; i++ )
sd->hate_mob[i] = -1;
sd->quest_log = NULL;
sd->num_quests = 0;
sd->avail_quests = 0;
sd->save_quest = false;
sd->count_rewarp = 0;
sd->regs.vars = i64db_alloc(DB_OPT_BASE);
sd->regs.arrays = NULL;
sd->vars_dirty = false;
sd->vars_ok = false;
sd->vars_received = 0x0;
sd->qi_display = NULL;
sd->qi_count = 0;
//warp player
if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != SETPOS_OK) {
ShowError ("Last_point_map %s - id %d not found (error code %d)\n", mapindex_id2name(sd->status.last_point.map), sd->status.last_point.map, i);
// try warping to a default map instead (church graveyard)
if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != SETPOS_OK) {
// if we fail again
clif_authfail_fd(sd->fd, 0);
return false;
}
}
clif_authok(sd);
//Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
sd->die_counter=-1;
//display login notice
ShowInfo("'" CL_WHITE "%s" CL_RESET "' logged in."
" (AID/CID: '" CL_WHITE "%d/%d" CL_RESET "',"
" IP: '" CL_WHITE "%d.%d.%d.%d" CL_RESET "',"
" Group '" CL_WHITE "%d" CL_RESET "').\n",
sd->status.name, sd->status.account_id, sd->status.char_id,
CONVIP(ip), sd->group_id);
// Send friends list
clif_friendslist_send(sd);
if( !changing_mapservers ) {
if (battle_config.display_version == 1)
pc_show_version(sd);
// Message of the Day [Valaris]
for(i=0; i < MOTD_LINE_SIZE && motd_text[i][0]; i++) {
if (battle_config.motd_type)
clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], motd_text[i], false, SELF);
else
clif_displaymessage(sd->fd, motd_text[i]);
}
if (expiration_time != 0)
sd->expiration_time = expiration_time;
/**
* Fixes login-without-aura glitch (the screen won't blink at this point, don't worry :P)
**/
clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
}
pc_validate_skill(sd);
/* [Ind] */
sd->sc_display = NULL;
sd->sc_display_count = 0;
// Player has not yet received the CashShop list
sd->status.cashshop_sent = false;
sd->last_addeditem_index = -1;
sd->bonus_script.head = NULL;
sd->bonus_script.count = 0;
#if PACKETVER >= 20150513
sd->hatEffectIDs = NULL;
sd->hatEffectCount = 0;
#endif
sd->catch_target_class = PET_CATCH_FAIL;
// Check EXP overflow, since in previous revision EXP on Max Level can be more than 'official' Max EXP
if (pc_is_maxbaselv(sd) && sd->status.base_exp > MAX_LEVEL_BASE_EXP) {
sd->status.base_exp = MAX_LEVEL_BASE_EXP;
clif_updatestatus(sd, SP_BASEEXP);
}
if (pc_is_maxjoblv(sd) && sd->status.job_exp > MAX_LEVEL_JOB_EXP) {
sd->status.job_exp = MAX_LEVEL_JOB_EXP;
clif_updatestatus(sd, SP_JOBEXP);
}
// Request all registries (auth is considered completed whence they arrive)
intif_request_registry(sd,7);
return true;
}
/*==========================================
* Closes a connection because it failed to be authenticated from the char server.
*------------------------------------------*/
void pc_authfail(struct map_session_data *sd)
{
clif_authfail_fd(sd->fd, 0);
return;
}
/**
* Player register a bl as hatred
* @param sd : player session
* @param pos : hate position [0;2]
* @param bl : target bl
* @return false:failed, true:success
*/
bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
{
int class_;
if (!sd || !bl || pos < 0 || pos > 2)
return false;
if (sd->hate_mob[pos] != -1)
{ //Can't change hate targets.
clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
return false;
}
class_ = status_get_class(bl);
if (!pcdb_checkid(class_)) {
unsigned int max_hp = status_get_max_hp(bl);
if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
return false;
if (pos != status_get_size(bl))
return false; //Wrong size
}
sd->hate_mob[pos] = class_;
pc_setglobalreg(sd, add_str(sg_info[pos].hate_var), class_+1);
clif_hate_info(sd, pos, class_, 1);
return true;
}
/*==========================================
* Invoked once after the char/account/account2 registry variables are received. [Skotlex]
* We didn't receive item information at this point so DO NOT attempt to do item operations here.
* See intif_parse_StorageReceived() for item operations [lighta]
*------------------------------------------*/
void pc_reg_received(struct map_session_data *sd)
{
uint8 i;
sd->vars_ok = true;
sd->change_level_2nd = pc_readglobalreg(sd, add_str(JOBCHANGE2ND_VAR));
sd->change_level_3rd = pc_readglobalreg(sd, add_str(JOBCHANGE3RD_VAR));
sd->die_counter = pc_readglobalreg(sd, add_str(PCDIECOUNTER_VAR));
sd->langtype = pc_readaccountreg(sd, add_str(LANGTYPE_VAR));
if (msg_checklangtype(sd->langtype,true) < 0)
sd->langtype = 0; //invalid langtype reset to default
// Cash shop
sd->cashPoints = pc_readaccountreg(sd, add_str(CASHPOINT_VAR));
sd->kafraPoints = pc_readaccountreg(sd, add_str(KAFRAPOINT_VAR));
// Cooking Exp
sd->cook_mastery = pc_readglobalreg(sd, add_str(COOKMASTERY_VAR));
if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
{ // Better check for class rather than skill to prevent "skill resets" from unsetting this
sd->mission_mobid = pc_readglobalreg(sd, add_str(TKMISSIONID_VAR));
sd->mission_count = pc_readglobalreg(sd, add_str(TKMISSIONCOUNT_VAR));
}
if (battle_config.feature_banking)
sd->bank_vault = pc_readreg2(sd, BANK_VAULT_VAR);
if (battle_config.feature_roulette) {
sd->roulette_point.bronze = pc_readreg2(sd, ROULETTE_BRONZE_VAR);
sd->roulette_point.silver = pc_readreg2(sd, ROULETTE_SILVER_VAR);
sd->roulette_point.gold = pc_readreg2(sd, ROULETTE_GOLD_VAR);
}
sd->roulette.prizeIdx = -1;
//SG map and mob read [Komurka]
for(i=0;i<MAX_PC_FEELHATE;i++) { //for now - someone need to make reading from txt/sql
uint16 j;
if ((j = pc_readglobalreg(sd, add_str(sg_info[i].feel_var))) != 0) {
sd->feel_map[i].index = j;
sd->feel_map[i].m = map_mapindex2mapid(j);
} else {
sd->feel_map[i].index = 0;
sd->feel_map[i].m = -1;
}
sd->hate_mob[i] = pc_readglobalreg(sd, add_str(sg_info[i].hate_var))-1;
}
if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
unsigned short skid = pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM));
sd->cloneskill_idx = skill_get_index(skid);
if (sd->cloneskill_idx > 0) {
sd->status.skill[sd->cloneskill_idx].id = skid;
sd->status.skill[sd->cloneskill_idx].lv = pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM_LV));
if (sd->status.skill[sd->cloneskill_idx].lv > i)
sd->status.skill[sd->cloneskill_idx].lv = i;
sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
}
}
if ((i = pc_checkskill(sd,SC_REPRODUCE)) > 0) {
unsigned short skid = pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE));
sd->reproduceskill_idx = skill_get_index(skid);
if (sd->reproduceskill_idx > 0) {
sd->status.skill[sd->reproduceskill_idx].id = skid;
sd->status.skill[sd->reproduceskill_idx].lv = pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE_LV));
if (i < sd->status.skill[sd->reproduceskill_idx].lv)
sd->status.skill[sd->reproduceskill_idx].lv = i;
sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
}
}
//Weird... maybe registries were reloaded?
if (sd->state.active)
return;
sd->state.active = 1;
sd->state.pc_loaded = false; // Ensure inventory data and status data is loaded before we calculate player stats
intif_storage_request(sd,TABLE_STORAGE, 0, STOR_MODE_ALL); // Request storage data
intif_storage_request(sd,TABLE_CART, 0, STOR_MODE_ALL); // Request cart data
intif_storage_request(sd,TABLE_INVENTORY, 0, STOR_MODE_ALL); // Request inventory data
if (sd->status.party_id)
party_member_joined(sd);
if (sd->status.guild_id)
guild_member_joined(sd);
if( sd->status.clan_id )
clan_member_joined(sd);
// pet
if (sd->status.pet_id > 0)
intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
// Homunculus [albator]
if( sd->status.hom_id > 0 )
intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
if( sd->status.mer_id > 0 )
intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
if( sd->status.ele_id > 0 )
intif_elemental_request(sd->status.ele_id, sd->status.char_id);
map_addiddb(&sd->bl);
map_delnickdb(sd->status.char_id, sd->status.name);
if (!chrif_auth_finished(sd))
ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
chrif_skillcooldown_request(sd->status.account_id, sd->status.char_id);
chrif_bsdata_request(sd->status.char_id);
#ifdef VIP_ENABLE
sd->vip.time = 0;
sd->vip.enabled = 0;
chrif_req_login_operation(sd->status.account_id, sd->status.name, CHRIF_OP_LOGIN_VIP, 0, 1|8, 0); // request VIP information
#endif
intif_Mail_requestinbox(sd->status.char_id, 0, MAIL_INBOX_NORMAL); // MAIL SYSTEM - Request Mail Inbox
intif_request_questlog(sd);
if (battle_config.feature_achievement) {
sd->achievement_data.total_score = 0;
sd->achievement_data.level = 0;
sd->achievement_data.save = false;
sd->achievement_data.count = 0;
sd->achievement_data.incompleteCount = 0;
sd->achievement_data.achievements = NULL;
intif_request_achievements(sd->status.char_id);
}
if (sd->state.connect_new == 0 && sd->fd) { //Character already loaded map! Gotta trigger LoadEndAck manually.
sd->state.connect_new = 1;
clif_parse_LoadEndAck(sd->fd, sd);
}
if( pc_isinvisible(sd) ) {
sd->vd.class_ = JT_INVISIBLE;
clif_displaymessage( sd->fd, msg_txt( sd, 11 ) ); // Invisible: On
// decrement the number of pvp players on the map
map_getmapdata(sd->bl.m)->users_pvp--;
if( map_getmapflag(sd->bl.m, MF_PVP) && !map_getmapflag(sd->bl.m, MF_PVP_NOCALCRANK) && sd->pvp_timer != INVALID_TIMER ){
// unregister the player for ranking
delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
sd->pvp_timer = INVALID_TIMER;
}
clif_changeoption( &sd->bl );
}
channel_autojoin(sd);
}
static int pc_calc_skillpoint(struct map_session_data* sd)
{
uint16 i, skill_point = 0;
nullpo_ret(sd);
for(i = 1; i < MAX_SKILL; i++) {
if( sd->status.skill[i].id && sd->status.skill[i].lv > 0) {
uint16 inf2 = skill_get_inf2(sd->status.skill[i].id);
if ((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
!(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex]
)
{
if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
skill_point += sd->status.skill[i].lv;
else if(sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0)
skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
}
}
}
return skill_point;
}
static bool pc_grant_allskills(struct map_session_data *sd, bool addlv) {
uint16 i = 0;
if (!sd || !pc_has_permission(sd, PC_PERM_ALL_SKILL) || !SKILL_MAX_DB())
return false;
/**
* Dummy skills must NOT be added here otherwise they'll be displayed in the,
* skill tree and since they have no icons they'll give resource errors
* Get ALL skills except npc/guild ones. [Skotlex]
* Don't add SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
**/
for( i = 0; i < MAX_SKILL; i++ ) {
uint16 skill_id = skill_idx2id(i);
if (!skill_id || (skill_get_inf2(skill_id)&(INF2_NPC_SKILL|INF2_GUILD_SKILL)))
continue;
switch (skill_id) {
case SM_SELFPROVOKE:
case AB_DUPLELIGHT_MELEE:
case AB_DUPLELIGHT_MAGIC:
case WL_CHAINLIGHTNING_ATK:
case WL_TETRAVORTEX_FIRE:
case WL_TETRAVORTEX_WATER:
case WL_TETRAVORTEX_WIND:
case WL_TETRAVORTEX_GROUND:
case WL_SUMMON_ATK_FIRE:
case WL_SUMMON_ATK_WIND:
case WL_SUMMON_ATK_WATER:
case WL_SUMMON_ATK_GROUND:
case LG_OVERBRAND_BRANDISH:
case LG_OVERBRAND_PLUSATK:
case WM_SEVERE_RAINSTORM_MELEE:
case RL_R_TRIP_PLUSATK:
case SG_DEVIL:
case MO_TRIPLEATTACK:
case RG_SNATCHER:
continue;
default:
{
uint8 lv = (uint8)skill_get_max(skill_id);
if (lv > 0) {
sd->status.skill[i].id = skill_id;
if (addlv)
sd->status.skill[i].lv = lv;
}
}
break;
}
}
return true;
}
/*==========================================
* Calculation of skill level.
* @param sd
*------------------------------------------*/
void pc_calc_skilltree(struct map_session_data *sd)
{
int i, flag;
int c = 0;
nullpo_retv(sd);
i = pc_calc_skilltree_normalize_job(sd);
c = pc_mapid2jobid(i, sd->status.sex);
if( c == -1 )
{ //Unable to normalize job??
ShowError("pc_calc_skilltree: Unable to normalize job %d for character %s (%d:%d)\n", i, sd->status.name, sd->status.account_id, sd->status.char_id);
return;
}
c = pc_class2idx(c);
for( i = 0; i < MAX_SKILL; i++ ) {
if( sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED ) //Don't touch these
sd->status.skill[i].id = 0; //First clear skills.
/* permanent skills that must be re-checked */
if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED ) {
uint16 sk_id = skill_idx2id(i);
if (!sk_id) {
sd->status.skill[i].id = 0;
sd->status.skill[i].lv = 0;
sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
continue;
}
switch (sk_id) {
case NV_TRICKDEAD:
if( (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ) {
sd->status.skill[i].id = 0;
sd->status.skill[i].lv = 0;
sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
}
break;
}
}
}
for( i = 0; i < MAX_SKILL; i++ ) {
uint16 skill_id = 0;
// Restore original level of skills after deleting earned skills.
if( sd->status.skill[i].flag != SKILL_FLAG_PERMANENT && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED ) {
sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
}
//Enable Bard/Dancer spirit linked skills.
if (!(skill_id = skill_idx2id(i)) || skill_id < DC_HUMMING || skill_id > DC_SERVICEFORYOU)
continue;
if( sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER ) {
//Link Dancer skills to bard.
if( sd->status.sex ) {
if( sd->status.skill[i-8].lv < 10 )
continue;
sd->status.skill[i].id = skill_id;
sd->status.skill[i].lv = sd->status.skill[i-8].lv; // Set the level to the same as the linking skill
sd->status.skill[i].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
}
//Link Bard skills to dancer.
else {
if( sd->status.skill[i].lv < 10 )
continue;
sd->status.skill[i-8].id = skill_id - 8;
sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
sd->status.skill[i-8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
}
}
}
// Removes Taekwon Ranker skill bonus
if ((sd->class_&MAPID_UPPERMASK) != MAPID_TAEKWON) {
uint16 c_ = pc_class2idx(JOB_TAEKWON);
for (i = 0; i < MAX_SKILL_TREE; i++) {
uint16 sk_id = skill_tree[c_][i].skill_id;
uint16 sk_idx = 0;
if (!sk_id || !(sk_idx = skill_get_index(skill_tree[c_][i].skill_id)))
continue;
if (sd->status.skill[sk_idx].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[sk_idx].flag != SKILL_FLAG_PERM_GRANTED) {
if (sk_id == NV_BASIC || sk_id == NV_FIRSTAID || sk_id == WE_CALLBABY)
continue;
sd->status.skill[sk_idx].id = 0;
}
}
}
// Grant all skills
pc_grant_allskills(sd, false);
do {
uint16 skid = 0;
flag = 0;
for (i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].skill_id) > 0; i++) {
bool fail = false;
uint16 sk_idx = skill_get_index(skid);
if (sd->status.skill[sk_idx].id)
continue; //Skill already known.
if (!battle_config.skillfree) {
uint8 j;
// Checking required skills
for(j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
uint16 sk_need_id = skill_tree[c][i].need[j].skill_id;
uint16 sk_need_idx = 0;
if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
short sk_need = sk_need_id;
if (sd->status.skill[sk_need_idx].id == 0 || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_PLAGIARIZED)
sk_need = 0; //Not learned.
else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real learned level
sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
else
sk_need = pc_checkskill(sd,sk_need_id);
if (sk_need < skill_tree[c][i].need[j].skill_lv) {
fail = true;
break;
}
}
}
if (sd->status.base_level < skill_tree[c][i].baselv) { //We need to get the actual class in this case
int class_ = pc_mapid2jobid(sd->class_, sd->status.sex);
class_ = pc_class2idx(class_);
if (class_ == c || (class_ != c && sd->status.base_level < skill_tree[class_][i].baselv))
fail = true; // base level requirement wasn't satisfied
}
if (sd->status.job_level < skill_tree[c][i].joblv) { //We need to get the actual class in this case
int class_ = pc_mapid2jobid(sd->class_, sd->status.sex);
class_ = pc_class2idx(class_);
if (class_ == c || (class_ != c && sd->status.job_level < skill_tree[class_][i].joblv))
fail = true; // job level requirement wasn't satisfied
}
}
if (!fail) {
int inf2 = skill_get_inf2(skid);
if (!sd->status.skill[sk_idx].lv && (
(inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
inf2&INF2_WEDDING_SKILL ||
(inf2&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
))
continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
sd->status.skill[sk_idx].id = skid;
if(inf2&INF2_SPIRIT_SKILL) { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
sd->status.skill[sk_idx].lv = 1; // need to manually specify a skill level
sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; //So it is not saved, and tagged as a "bonus" skill.
}
flag = 1; // skill list has changed, perform another pass
}
}
} while(flag);
if( c > 0 && sd->status.skill_point == 0 && pc_is_taekwon_ranker(sd) ) {
unsigned short skid = 0;
/* Taekwon Ranker Bonus Skill Tree
============================================
- Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
- (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
- (sd->status.skill_point == 0) to wait until all skill points are assigned to avoid problems with Job Change quest. */
for( i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].skill_id) > 0; i++ ) {
uint16 sk_idx = 0;
if (!(sk_idx = skill_get_index(skid)))
continue;
if( (skill_get_inf2(skid)&(INF2_QUEST_SKILL|INF2_WEDDING_SKILL)) )
continue; //Do not include Quest/Wedding skills.
if( sd->status.skill[sk_idx].id == 0 ) {
sd->status.skill[sk_idx].id = skid;
sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; // So it is not saved, and tagged as a "bonus" skill.
} else if( skid != NV_BASIC )
sd->status.skill[sk_idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[sk_idx].lv; // Remember original level
sd->status.skill[sk_idx].lv = skill_tree_get_max(skid, sd->status.class_);
}
}
}
//Checks if you can learn a new skill after having leveled up a skill.
static void pc_check_skilltree(struct map_session_data *sd)
{
int i, flag = 0;
int c = 0;
if (battle_config.skillfree)
return; //Function serves no purpose if this is set
i = pc_calc_skilltree_normalize_job(sd);
c = pc_mapid2jobid(i, sd->status.sex);
if (c == -1) { //Unable to normalize job??
ShowError("pc_check_skilltree: Unable to normalize job %d for character %s (%d:%d)\n", i, sd->status.name, sd->status.account_id, sd->status.char_id);
return;
}
c = pc_class2idx(c);
do {
uint16 skid = 0;
flag = 0;
for (i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].skill_id) > 0; i++ ) {
uint16 sk_idx = skill_get_index(skid);
bool fail = false;
uint8 j = 0;
if (sd->status.skill[sk_idx].id) //Already learned
continue;
// Checking required skills
for (j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
uint16 sk_need_id = skill_tree[c][i].need[j].skill_id;
uint16 sk_need_idx = 0;
if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
short sk_need = sk_need_id;
if (sd->status.skill[sk_need_idx].id == 0 || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_PLAGIARIZED)
sk_need = 0; //Not learned.
else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
else
sk_need = pc_checkskill(sd,sk_need_id);
if (sk_need < skill_tree[c][i].need[j].skill_lv) {
fail = true;
break;
}
}
}
if( fail )
continue;
if (sd->status.base_level < skill_tree[c][i].baselv || sd->status.job_level < skill_tree[c][i].joblv)
continue;
j = skill_get_inf2(skid);
if( !sd->status.skill[sk_idx].lv && (
(j&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
j&INF2_WEDDING_SKILL ||
(j&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
) )
continue; //Cannot be learned via normal means.
sd->status.skill[sk_idx].id = skid;
flag = 1;
}
} while(flag);
}
// Make sure all the skills are in the correct condition
// before persisting to the backend.. [MouseJstr]
void pc_clean_skilltree(struct map_session_data *sd)
{
uint16 i;
for (i = 0; i < MAX_SKILL; i++){
if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED) {
sd->status.skill[i].id = 0;
sd->status.skill[i].lv = 0;
sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
}
else if (sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0){
sd->status.skill[i].lv = sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
}
}
}
int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
{
int skill_point, novice_skills;
int c = sd->class_;
if (!battle_config.skillup_limit || pc_has_permission(sd, PC_PERM_ALL_SKILL))
return c;
skill_point = pc_calc_skillpoint(sd);
novice_skills = job_info[pc_class2idx(JOB_NOVICE)].max_level[1] - 1;
// limit 1st class and above to novice job levels
if(skill_point < novice_skills && (sd->class_&MAPID_BASEMASK) != MAPID_SUMMONER)
{
c = MAPID_NOVICE;
}
// limit 2nd class and above to first class job levels (super novices are exempt)
else if (sd->class_&JOBL_2 && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE)
{
// regenerate change_level_2nd
if (!sd->change_level_2nd)
{
if (sd->class_&JOBL_THIRD)
{
// if neither 2nd nor 3rd jobchange levels are known, we have to assume a default for 2nd
if (!sd->change_level_3rd)
sd->change_level_2nd = job_info[pc_class2idx(pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex))].max_level[1];
else
sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
- (sd->status.job_level - 1)
- (sd->change_level_3rd - 1)
- novice_skills;
}
else
{
sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
- (sd->status.job_level - 1)
- novice_skills;
}
pc_setglobalreg(sd, add_str(JOBCHANGE2ND_VAR), sd->change_level_2nd);
}
if (skill_point < novice_skills + (sd->change_level_2nd - 1))
{
c &= MAPID_BASEMASK;
}
// limit 3rd class to 2nd class/trans job levels
else if(sd->class_&JOBL_THIRD)
{
// regenerate change_level_3rd
if (!sd->change_level_3rd)
{
sd->change_level_3rd = 1 + skill_point + sd->status.skill_point
- (sd->status.job_level - 1)
- (sd->change_level_2nd - 1)
- novice_skills;
pc_setglobalreg(sd, add_str(JOBCHANGE3RD_VAR), sd->change_level_3rd);
}
if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1))
c &= MAPID_UPPERMASK;
}
}
// restore non-limiting flags
c |= sd->class_&(JOBL_UPPER|JOBL_BABY);
return c;
}
/*==========================================
* Updates the weight status
*------------------------------------------
* 1: overweight 50% for pre-renewal and 70% for renewal
* 2: overweight 90%
* It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
*/
void pc_updateweightstatus(struct map_session_data *sd)
{
int old_overweight;
int new_overweight;
nullpo_retv(sd);
old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
#ifdef RENEWAL
new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is70overweight(sd)) ? 1 : 0;
#else
new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
#endif
if( old_overweight == new_overweight )
return; // no change
// stop old status change
if( old_overweight == 1 )
status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
else if( old_overweight == 2 )
status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
// start new status change
if( new_overweight == 1 )
sc_start(&sd->bl,&sd->bl, SC_WEIGHT50, 100, 0, 0);
else if( new_overweight == 2 )
sc_start(&sd->bl,&sd->bl, SC_WEIGHT90, 100, 0, 0);
// update overweight status
sd->regen.state.overweight = new_overweight;
}
int pc_disguise(struct map_session_data *sd, int class_)
{
if (!class_ && !sd->disguise)
return 0;
if (class_ && sd->disguise == class_)
return 0;
if(pc_isinvisible(sd))
{ //Character is invisible. Stealth class-change. [Skotlex]
sd->disguise = class_; //viewdata is set on uncloaking.
return 2;
}
if (sd->bl.prev != NULL) {
pc_stop_walking(sd, 0);
clif_clearunit_area(&sd->bl, CLR_OUTSIGHT);
}
if (!class_) {
sd->disguise = 0;
class_ = sd->status.class_;
} else
sd->disguise=class_;
status_set_viewdata(&sd->bl, class_);
clif_changeoption(&sd->bl);
if (sd->bl.prev != NULL) {
clif_spawn(&sd->bl);
if (class_ == sd->status.class_ && pc_iscarton(sd))
{ //It seems the cart info is lost on undisguise.
clif_cartlist(sd);
clif_updatestatus(sd,SP_CARTINFO);
}
if (sd->chatID) {
struct chat_data* cd;
if ((cd = (struct chat_data*)map_id2bl(sd->chatID)) != NULL)
clif_dispchat(cd,0);
}
}
return 1;
}
/// Show error message
#define PC_BONUS_SHOW_ERROR(type,type2,val) { ShowError("%s: %s: Invalid %s %d.\n",__FUNCTION__,#type,#type2,(val)); break; }
/// Check for valid Element, break & show error message if invalid Element
#define PC_BONUS_CHK_ELEMENT(ele,bonus) { if (!CHK_ELEMENT((ele))) { PC_BONUS_SHOW_ERROR((bonus),Element,(ele)); }}
/// Check for valid Race, break & show error message if invalid Race
#define PC_BONUS_CHK_RACE(rc,bonus) { if (!CHK_RACE((rc))) { PC_BONUS_SHOW_ERROR((bonus),Race,(rc)); }}
/// Check for valid Race2, break & show error message if invalid Race2
#define PC_BONUS_CHK_RACE2(rc2,bonus) { if (!CHK_RACE2((rc2))) { PC_BONUS_SHOW_ERROR((bonus),Race2,(rc2)); }}
/// Check for valid Class, break & show error message if invalid Class
#define PC_BONUS_CHK_CLASS(cl,bonus) { if (!CHK_CLASS((cl))) { PC_BONUS_SHOW_ERROR((bonus),Class,(cl)); }}
/// Check for valid Size, break & show error message if invalid Size
#define PC_BONUS_CHK_SIZE(sz,bonus) { if (!CHK_MOBSIZE((sz))) { PC_BONUS_SHOW_ERROR((bonus),Size,(sz)); }}
/// Check for valid SC, break & show error message if invalid SC
#define PC_BONUS_CHK_SC(sc,bonus) { if ((sc) <= SC_NONE || (sc) >= SC_MAX) { PC_BONUS_SHOW_ERROR((bonus),Effect,(sc)); }}
/**
* Add auto spell bonus for player while attacking/attacked
* @param spell: Spell array
* @param id: Skill to cast
* @param lv: Skill level
* @param rate: Success chance
* @param flag: Battle flag
* @param card_id: Used to prevent card stacking
*/
static void pc_bonus_autospell(std::vector<s_autospell> &spell, short id, short lv, short rate, short flag, unsigned short card_id)
{
if (spell.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_autospell: Reached max (%d) number of autospells per character!\n", MAX_PC_BONUS);
return;
}
if (!rate)
return;
if (!(flag&BF_RANGEMASK))
flag |= BF_SHORT | BF_LONG; //No range defined? Use both.
if (!(flag&BF_WEAPONMASK))
flag |= BF_WEAPON; //No attack type defined? Use weapon.
if (!(flag&BF_SKILLMASK)) {
if (flag&(BF_MAGIC | BF_MISC))
flag |= BF_SKILL; //These two would never trigger without BF_SKILL
if (flag&BF_WEAPON)
flag |= BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
}
for (auto &it : spell) {
if ((it.card_id == card_id || it.rate < 0 || rate < 0) && it.id == id && it.lv == lv && it.flag == flag) {
if (!battle_config.autospell_stacking && it.rate > 0 && rate > 0) // Stacking disabled
return;
it.rate = cap_value(it.rate + rate, -10000, 10000);
return;
}
}
struct s_autospell entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_autospell: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.id = id;
entry.lv = lv;
entry.rate = cap_value(rate, -10000, 10000);
entry.flag = flag;
entry.card_id = card_id;
spell.push_back(entry);
}
/**
* Add auto spell bonus for player while using skills
* @param spell: Spell array
* @param src_skill: Trigger skill
* @param id: Support or target type
* @param lv: Skill level
* @param rate: Success chance
* @param card_id: Used to prevent card stacking
*/
static void pc_bonus_autospell_onskill(std::vector<s_autospell> &spell, short src_skill, short id, short lv, short rate, unsigned short card_id)
{
if (spell.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_autospell_onskill: Reached max (%d) number of autospells per character!\n", MAX_PC_BONUS);
return;
}
if (!rate)
return;
struct s_autospell entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_onskill: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.flag = src_skill;
entry.id = id;
entry.lv = lv;
entry.rate = cap_value(rate, -10000, 10000);
entry.card_id = card_id;
spell.push_back(entry);
}
/**
* Add inflict effect bonus for player while attacking/attacked
* @param effect: Effect array
* @param sc: SC/Effect type
* @param rate: Success chance
* @param arrow_rate: success chance if bonus comes from arrow-type item
* @param flag: Target flag
* @param duration: Duration. If 0 use default duration lookup for associated skill with level 7
*/
static void pc_bonus_addeff(std::vector<s_addeffect> &effect, enum sc_type sc, short rate, short arrow_rate, unsigned char flag, unsigned int duration)
{
if (effect.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_addeff: Reached max (%d) number of add effects per character!\n", MAX_PC_BONUS);
return;
}
if (!(flag&(ATF_SHORT | ATF_LONG)))
flag |= ATF_SHORT | ATF_LONG; //Default range: both
if (!(flag&(ATF_TARGET | ATF_SELF)))
flag |= ATF_TARGET; //Default target: enemy.
if (!(flag&(ATF_WEAPON | ATF_MAGIC | ATF_MISC)))
flag |= ATF_WEAPON; //Default type: weapon.
if (!duration)
duration = (unsigned int)skill_get_time2(status_sc2skill(sc), 7);
for (auto &it : effect) {
if (it.sc == sc && it.flag == flag) {
it.rate = cap_value(it.rate + rate, -10000, 10000);
it.arrow_rate += arrow_rate;
it.duration = umax(it.duration, duration);
return;
}
}
struct s_addeffect entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_addeff: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.sc = sc;
entry.rate = cap_value(rate, -10000, 10000);
entry.arrow_rate = arrow_rate;
entry.flag = flag;
entry.duration = duration;
effect.push_back(entry);
}
/**
* Add inflict effect bonus for player while attacking using skill
* @param effect: Effect array
* @param sc: SC/Effect type
* @param rate: Success chance
* @param skill_id: Skill to cast
* @param target: Target type
* @param duration: Duration. If 0 use default duration lookup for associated skill with level 7
*/
static void pc_bonus_addeff_onskill(std::vector<s_addeffectonskill> &effect, enum sc_type sc, short rate, short skill_id, unsigned char target, unsigned int duration)
{
if (effect.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_addeff_onskill: Reached max (%d) number of add effects per character!\n", MAX_PC_BONUS);
return;
}
if (!duration)
duration = (unsigned int)skill_get_time2(status_sc2skill(sc), 7);
for (auto &it : effect) {
if (it.sc == sc && it.skill_id == skill_id && it.target == target) {
it.rate = cap_value(it.rate + rate, -10000, 10000);
it.duration = umax(it.duration, duration);
return;
}
}
struct s_addeffectonskill entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_addeff_onskill: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.sc = sc;
entry.rate = cap_value(rate, -10000, 10000);
entry.skill_id = skill_id;
entry.target = target;
entry.duration = duration;
effect.push_back(entry);
}
/**
* Adjust/add drop rate modifier for player
* @param drop: Player's sd->add_drop (struct s_add_drop)
* @param nameid: item id that will be dropped
* @param group: group id
* @param class_: target class
* @param race: target race. if < 0, means monster_id
* @param rate: rate value: 1 ~ 10000. If < 0, it will be multiplied with mob level/10
*/
static void pc_bonus_item_drop(std::vector<s_add_drop> &drop, unsigned short nameid, uint16 group, int class_, short race, int rate)
{
if (!nameid && !group) {
ShowWarning("pc_bonus_item_drop: No Item ID nor Item Group ID specified.\n");
return;
}
if (nameid && !itemdb_exists(nameid)) {
ShowWarning("pc_bonus_item_drop: Invalid item id %hu\n",nameid);
return;
}
if (group && !itemdb_group_exists(group)) {
ShowWarning("pc_bonus_item_drop: Invalid Item Group %hu\n",group);
return;
}
if (drop.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_item_drop: Reached max (%d) number of added drops per character! (nameid: %hu group: %d class_: %d race: %d rate: %d)\n", MAX_PC_BONUS, nameid, group, class_, race, rate);
return;
}
//Apply config rate adjustment settings.
if (rate >= 0) { //Absolute drop.
if (battle_config.item_rate_adddrop != 100)
rate = rate*battle_config.item_rate_adddrop/100;
if (rate < battle_config.item_drop_adddrop_min)
rate = battle_config.item_drop_adddrop_min;
else if (rate > battle_config.item_drop_adddrop_max)
rate = battle_config.item_drop_adddrop_max;
} else { //Relative drop, max/min limits are applied at drop time.
if (battle_config.item_rate_adddrop != 100)
rate = rate*battle_config.item_rate_adddrop/100;
if (rate > -1)
rate = -1;
}
for (auto &it : drop) {
if (it.nameid == nameid && it.group == group && it.race == race && it.class_ == class_) {
if ((rate < 0 && it.rate < 0) || (rate > 0 && it.rate > 0)) //Adjust the rate if it has same classification
it.rate = cap_value(it.rate + rate, -10000, 10000);
return;
}
}
struct s_add_drop entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_item_drop: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.nameid = nameid;
entry.group = group;
entry.race = race;
entry.class_ = class_;
entry.rate = cap_value(rate, -10000, 10000);
drop.push_back(entry);
}
/**
* Add autobonus to player when attacking/attacked
* @param bonus: Bonus array
* @param script: Script to execute
* @param rate: Success chance
* @param dur: Duration
* @param flag: Battle flag/skill
* @param other_script: Secondary script to execute
* @param pos: Item equip position
* @param onskill: Skill used to trigger autobonus
* @return True on success or false otherwise
*/
bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, uint16 flag, const char *other_script, unsigned int pos, bool onskill)
{
if (bonus.size() == MAX_PC_BONUS) {
ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", MAX_PC_BONUS);
return false;
}
if (!onskill) {
if (!(flag&BF_RANGEMASK))
flag |= BF_SHORT | BF_LONG; //No range defined? Use both.
if (!(flag&BF_WEAPONMASK))
flag |= BF_WEAPON; //No attack type defined? Use weapon.
if (!(flag&BF_SKILLMASK)) {
if (flag&(BF_MAGIC | BF_MISC))
flag |= BF_SKILL; //These two would never trigger without BF_SKILL
if (flag&BF_WEAPON)
flag |= BF_NORMAL | BF_SKILL;
}
}
struct s_autobonus entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_addautobonus: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.rate = cap_value(rate, -10000, 10000);
entry.duration = dur;
entry.active = INVALID_TIMER;
entry.atk_type = flag;
entry.pos = pos;
entry.bonus_script = aStrdup(script);
entry.other_script = (other_script ? aStrdup(other_script) : NULL);
bonus.push_back(entry);
return true;
}
/**
* Remove an autobonus from player
* @param sd: Player data
* @param bonus: Autobonus array
* @param restore: Run script on clearing or not
*/
void pc_delautobonus(struct map_session_data* sd, std::vector<s_autobonus> &bonus, bool restore)
{
nullpo_retv(sd);
std::vector<s_autobonus>::iterator it = bonus.begin();
while( it != bonus.end() ){
s_autobonus b = *it;
if (b.active != INVALID_TIMER) {
if (restore && (sd->state.autobonus&b.pos) == b.pos) {
if (b.bonus_script) {
unsigned int equip_pos_idx = 0;
// Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
for (uint8 j = 0; j < EQI_MAX; j++) {
if (sd->equip_index[j] >= 0)
equip_pos_idx |= sd->inventory.u.items_inventory[sd->equip_index[j]].equip;
}
if ((equip_pos_idx&b.pos) == b.pos)
script_run_autobonus(b.bonus_script, sd, b.pos);
}
it++;
continue;
} else { // Logout / Unequipped an item with an activated bonus
delete_timer(b.active, pc_endautobonus);
b.active = INVALID_TIMER;
}
}
if (b.bonus_script)
aFree(b.bonus_script);
if (b.other_script)
aFree(b.other_script);
it = bonus.erase(it);
}
}
/**
* Execute autobonus on player
* @param sd: Player data
* @param autobonus: Autobonus to run
*/
void pc_exeautobonus(struct map_session_data *sd, std::vector<s_autobonus> *bonus, struct s_autobonus *autobonus)
{
nullpo_retv(sd);
nullpo_retv(autobonus);
if (autobonus->active != INVALID_TIMER)
delete_timer(autobonus->active, pc_endautobonus);
if( autobonus->other_script )
{
int j;
unsigned int equip_pos_idx = 0;
//Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
for(j = 0; j < EQI_MAX; j++) {
if(sd->equip_index[j] >= 0)
equip_pos_idx |= sd->inventory.u.items_inventory[sd->equip_index[j]].equip;
}
if((equip_pos_idx&autobonus->pos) == autobonus->pos)
script_run_autobonus(autobonus->other_script,sd,autobonus->pos);
}
autobonus->active = add_timer(gettick()+autobonus->duration, pc_endautobonus, sd->bl.id, (intptr_t)bonus);
sd->state.autobonus |= autobonus->pos;
status_calc_pc(sd,SCO_FORCE);
}
/**
* Remove autobonus timer from player
*/
TIMER_FUNC(pc_endautobonus){
struct map_session_data *sd = map_id2sd(id);
std::vector<s_autobonus> *bonus = (std::vector<s_autobonus> *)data;
nullpo_ret(sd);
nullpo_ret(bonus);
for( struct s_autobonus& autobonus : *bonus ){
if( autobonus.active == tid ){
autobonus.active = INVALID_TIMER;
sd->state.autobonus &= ~autobonus.pos;
break;
}
}
status_calc_pc(sd,SCO_FORCE);
return 0;
}
/**
* Add element bonus to player when attacking
* @param sd: Player data
* @param ele: Element to adjust
* @param rate: Success chance
* @param flag: Battle flag
*/
static void pc_bonus_addele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
{
nullpo_retv(sd);
struct weapon_data *wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
if (wd->addele2.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_addele: Reached max (%d) number of add element damage bonuses per character!\n", MAX_PC_BONUS);
return;
}
if (!(flag&BF_RANGEMASK))
flag |= BF_SHORT | BF_LONG;
if (!(flag&BF_WEAPONMASK))
flag |= BF_WEAPON;
if (!(flag&BF_SKILLMASK)) {
if (flag&(BF_MAGIC | BF_MISC))
flag |= BF_SKILL;
if (flag&BF_WEAPON)
flag |= BF_NORMAL | BF_SKILL;
}
for (auto &it : wd->addele2) {
if (it.ele == ele && it.flag == flag) {
it.rate = cap_value(it.rate + rate, -10000, 10000);
return;
}
}
struct s_addele2 entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_addele: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.ele = ele;
entry.rate = cap_value(rate, -10000, 10000);
entry.flag = flag;
wd->addele2.push_back(entry);
}
/**
* Reduce element bonus to player when attacking
* @param sd: Player data
* @param ele: Element to adjust
* @param rate: Success chance
* @param flag: Battle flag
*/
static void pc_bonus_subele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
{
nullpo_retv(sd);
if (sd->subele2.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_subele: Reached max (%d) number of resist element damage bonuses per character!\n", MAX_PC_BONUS);
return;
}
if (!(flag&BF_RANGEMASK))
flag |= BF_SHORT | BF_LONG;
if (!(flag&BF_WEAPONMASK))
flag |= BF_WEAPON;
if (!(flag&BF_SKILLMASK)) {
if (flag&(BF_MAGIC | BF_MISC))
flag |= BF_SKILL;
if (flag&BF_WEAPON)
flag |= BF_NORMAL | BF_SKILL;
}
for (auto &it : sd->subele2) {
if (it.ele == ele && it.flag == flag) {
it.rate = cap_value(it.rate + rate, -10000, 10000);
return;
}
}
struct s_addele2 entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_subele: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.ele = ele;
entry.rate = cap_value(rate, -10000, 10000);
entry.flag = flag;
sd->subele2.push_back(entry);
}
/**
* General item bonus for player
* @param bonus: Bonus array
* @param id: Key
* @param val: Value
* @param cap_rate: If Value is a rate value that needs to be capped
*/
static void pc_bonus_itembonus(std::vector<s_item_bonus> &bonus, uint16 id, int val, bool cap_rate)
{
for (auto &it : bonus) {
if (it.id == id) {
if (cap_rate)
it.val = cap_value(it.val + val, -10000, 10000);
else
it.val += val;
return;
}
}
struct s_item_bonus entry = {};
if (cap_rate && (val < -10000 || val > 10000)) {
ShowWarning("pc_bonus_itembonus: Item bonus val %d exceeds -10000~10000 range, capping.\n", val);
val = cap_value(val, -10000, 10000);
}
entry.id = id;
entry.val = val;
bonus.push_back(entry);
}
/**
* Remove HP/SP to player when attacking
* @param bonus: Bonus array
* @param rate: Success chance
* @param per: Percentage of HP/SP to vanish
* @param flag: Battle flag
*/
static void pc_bonus_addvanish(std::vector<s_vanish_bonus> &bonus, int16 rate, int16 per, int flag) {
if (bonus.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus_addvanish: Reached max (%d) number of vanish damage bonuses per character!\n", MAX_PC_BONUS);
return;
}
if (!(flag&BF_RANGEMASK))
flag |= BF_SHORT | BF_LONG;
if (!(flag&BF_WEAPONMASK))
flag |= BF_WEAPON;
if (!(flag&BF_SKILLMASK)) {
if (flag&(BF_MAGIC | BF_MISC))
flag |= BF_SKILL;
if (flag&BF_WEAPON)
flag |= BF_NORMAL | BF_SKILL;
}
for (auto &it : bonus) {
if (it.flag == flag) {
it.rate = cap_value(it.rate + rate, -10000, 10000);
it.per += per;
return;
}
}
struct s_vanish_bonus entry = {};
if (rate < -10000 || rate > 10000)
ShowWarning("pc_bonus_addvanish: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
entry.rate = cap_value(rate, -10000, 10000);
entry.per = per;
entry.flag = flag;
bonus.push_back(entry);
}
/*==========================================
* Add a bonus(type) to player sd
* format: bonus bBonusName,val;
* @param sd
* @param type Bonus type used by bBonusName
* @param val Value that usually for rate or fixed value
*------------------------------------------*/
void pc_bonus(struct map_session_data *sd,int type,int val)
{
struct status_data *status;
int bonus;
nullpo_retv(sd);
status = &sd->base_status;
switch(type){
case SP_STR:
case SP_AGI:
case SP_VIT:
case SP_INT:
case SP_DEX:
case SP_LUK:
if(sd->state.lr_flag != 2)
sd->param_bonus[type-SP_STR]+=val;
break;
case SP_ATK1:
if(!sd->state.lr_flag) {
bonus = status->rhw.atk + val;
status->rhw.atk = cap_value(bonus, 0, USHRT_MAX);
}
else if(sd->state.lr_flag == 1) {
bonus = status->lhw.atk + val;
status->lhw.atk = cap_value(bonus, 0, USHRT_MAX);
}
break;
case SP_ATK2:
if(!sd->state.lr_flag) {
bonus = status->rhw.atk2 + val;
status->rhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
}
else if(sd->state.lr_flag == 1) {
bonus = status->lhw.atk2 + val;
status->lhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
}
break;
case SP_BASE_ATK:
if(sd->state.lr_flag != 2) {
#ifdef RENEWAL
bonus = sd->bonus.eatk + val;
sd->bonus.eatk = cap_value(bonus, SHRT_MIN, SHRT_MAX);
#else
bonus = status->batk + val;
status->batk = cap_value(bonus, 0, USHRT_MAX);
#endif
}
break;
case SP_DEF1:
if(sd->state.lr_flag != 2) {
bonus = status->def + val;
#ifdef RENEWAL
status->def = cap_value(bonus, SHRT_MIN, SHRT_MAX);
#else
status->def = cap_value(bonus, CHAR_MIN, CHAR_MAX);
#endif
}
break;
case SP_DEF2:
if(sd->state.lr_flag != 2) {
bonus = status->def2 + val;
status->def2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
}
break;
case SP_MDEF1:
if(sd->state.lr_flag != 2) {
bonus = status->mdef + val;
#ifdef RENEWAL
status->mdef = cap_value(bonus, SHRT_MIN, SHRT_MAX);
#else
status->mdef = cap_value(bonus, CHAR_MIN, CHAR_MAX);
#endif
if( sd->state.lr_flag == 3 ) {//Shield, used for royal guard
sd->bonus.shieldmdef += bonus;
}
}
break;
case SP_MDEF2:
if(sd->state.lr_flag != 2) {
bonus = status->mdef2 + val;
status->mdef2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
}
break;
case SP_HIT:
if(sd->state.lr_flag != 2) {
bonus = status->hit + val;
status->hit = cap_value(bonus, SHRT_MIN, SHRT_MAX);
} else
sd->bonus.arrow_hit+=val;
break;
case SP_FLEE1:
if(sd->state.lr_flag != 2) {
bonus = status->flee + val;
status->flee = cap_value(bonus, SHRT_MIN, SHRT_MAX);
}
break;
case SP_FLEE2:
if(sd->state.lr_flag != 2) {
bonus = status->flee2 + val*10;
status->flee2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
}
break;
case SP_CRITICAL:
if(sd->state.lr_flag != 2) {
bonus = status->cri + val*10;
status->cri = cap_value(bonus, SHRT_MIN, SHRT_MAX);
} else
sd->bonus.arrow_cri += val*10;
break;
case SP_ATKELE:
PC_BONUS_CHK_ELEMENT(val,SP_ATKELE);
switch (sd->state.lr_flag)
{
case 2:
switch (sd->status.weapon) {
case W_BOW:
case W_REVOLVER:
case W_RIFLE:
case W_GATLING:
case W_SHOTGUN:
case W_GRENADE:
//Become weapon element.
status->rhw.ele=val;
break;
default: //Become arrow element.
sd->bonus.arrow_ele=val;
break;
}
break;
case 1:
status->lhw.ele=val;
break;
default:
status->rhw.ele=val;
break;
}
break;
case SP_DEFELE:
PC_BONUS_CHK_ELEMENT(val,SP_DEFELE);
if(sd->state.lr_flag != 2)
status->def_ele=val;
break;
case SP_MAXHP:
if(sd->state.lr_flag == 2)
break;
sd->bonus.hp += val;
break;
case SP_MAXSP:
if(sd->state.lr_flag == 2)
break;
sd->bonus.sp += val;
break;
case SP_MAXHPRATE:
if(sd->state.lr_flag != 2)
sd->hprate+=val;
break;
case SP_MAXSPRATE:
if(sd->state.lr_flag != 2)
sd->sprate+=val;
break;
case SP_SPRATE:
if(sd->state.lr_flag != 2)
sd->dsprate+=val;
break;
case SP_ATTACKRANGE:
switch (sd->state.lr_flag) {
case 2:
switch (sd->status.weapon) {
case W_BOW:
case W_REVOLVER:
case W_RIFLE:
case W_GATLING:
case W_SHOTGUN:
case W_GRENADE:
status->rhw.range += val;
}
break;
case 1:
status->lhw.range += val;
break;
default:
status->rhw.range += val;
break;
}
break;
case SP_SPEED_RATE: //Non stackable increase
if(sd->state.lr_flag != 2)
sd->bonus.speed_rate = min(sd->bonus.speed_rate, -val);
break;
case SP_SPEED_ADDRATE: //Stackable increase
if(sd->state.lr_flag != 2)
sd->bonus.speed_add_rate -= val;
break;
case SP_ASPD: //Raw increase
if(sd->state.lr_flag != 2)
sd->bonus.aspd_add -= 10*val;
break;
case SP_ASPD_RATE: //Stackable increase - Made it linear as per rodatazone
if(sd->state.lr_flag != 2)
#ifndef RENEWAL_ASPD
status->aspd_rate -= 10*val;
#else
status->aspd_rate2 += val;
#endif
break;
case SP_HP_RECOV_RATE:
if(sd->state.lr_flag != 2)
sd->hprecov_rate += val;
break;
case SP_SP_RECOV_RATE:
if(sd->state.lr_flag != 2)
sd->sprecov_rate += val;
break;
case SP_CRITICAL_DEF:
if(sd->state.lr_flag != 2)
sd->bonus.critical_def += val;
break;
case SP_NEAR_ATK_DEF:
if(sd->state.lr_flag != 2)
sd->bonus.near_attack_def_rate += val;
break;
case SP_LONG_ATK_DEF:
if(sd->state.lr_flag != 2)
sd->bonus.long_attack_def_rate += val;
break;
case SP_DOUBLE_RATE:
if(sd->state.lr_flag == 0 && sd->bonus.double_rate < val)
sd->bonus.double_rate = val;
break;
case SP_DOUBLE_ADD_RATE:
if(sd->state.lr_flag == 0)
sd->bonus.double_add_rate += val;
break;
case SP_MATK_RATE:
if(sd->state.lr_flag != 2)
sd->matk_rate += val;
break;
case SP_IGNORE_DEF_ELE:
PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_DEF_ELE);
if(!sd->state.lr_flag)
sd->right_weapon.ignore_def_ele |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.ignore_def_ele |= 1<<val;
break;
case SP_IGNORE_DEF_RACE:
PC_BONUS_CHK_RACE(val,SP_IGNORE_DEF_RACE);
if(!sd->state.lr_flag)
sd->right_weapon.ignore_def_race |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.ignore_def_race |= 1<<val;
break;
case SP_IGNORE_DEF_CLASS:
PC_BONUS_CHK_CLASS(val,SP_IGNORE_DEF_CLASS);
if(!sd->state.lr_flag)
sd->right_weapon.ignore_def_class |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.ignore_def_class |= 1<<val;
break;
case SP_ATK_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.atk_rate += val;
break;
case SP_MAGIC_ATK_DEF:
if(sd->state.lr_flag != 2)
sd->bonus.magic_def_rate += val;
break;
case SP_MISC_ATK_DEF:
if(sd->state.lr_flag != 2)
sd->bonus.misc_def_rate += val;
break;
case SP_IGNORE_MDEF_ELE:
PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_MDEF_ELE);
if(sd->state.lr_flag != 2)
sd->bonus.ignore_mdef_ele |= 1<<val;
break;
case SP_IGNORE_MDEF_RACE:
PC_BONUS_CHK_RACE(val,SP_IGNORE_MDEF_RACE);
if(sd->state.lr_flag != 2)
sd->bonus.ignore_mdef_race |= 1<<val;
break;
case SP_PERFECT_HIT_RATE:
if(sd->state.lr_flag != 2 && sd->bonus.perfect_hit < val)
sd->bonus.perfect_hit = val;
break;
case SP_PERFECT_HIT_ADD_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.perfect_hit_add += val;
break;
case SP_CRITICAL_RATE:
if(sd->state.lr_flag != 2)
sd->critical_rate+=val;
break;
case SP_DEF_RATIO_ATK_ELE:
PC_BONUS_CHK_ELEMENT(val,SP_DEF_RATIO_ATK_ELE);
if(!sd->state.lr_flag)
sd->right_weapon.def_ratio_atk_ele |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.def_ratio_atk_ele |= 1<<val;
break;
case SP_DEF_RATIO_ATK_RACE:
PC_BONUS_CHK_RACE(val,SP_DEF_RATIO_ATK_RACE);
if(!sd->state.lr_flag)
sd->right_weapon.def_ratio_atk_race |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.def_ratio_atk_race |= 1<<val;
break;
case SP_DEF_RATIO_ATK_CLASS:
PC_BONUS_CHK_CLASS(val,SP_DEF_RATIO_ATK_CLASS);
if(!sd->state.lr_flag)
sd->right_weapon.def_ratio_atk_class |= 1<<val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.def_ratio_atk_class |= 1<<val;
break;
case SP_HIT_RATE:
if(sd->state.lr_flag != 2)
sd->hit_rate += val;
break;
case SP_FLEE_RATE:
if(sd->state.lr_flag != 2)
sd->flee_rate += val;
break;
case SP_FLEE2_RATE:
if(sd->state.lr_flag != 2)
sd->flee2_rate += val;
break;
case SP_DEF_RATE:
if(sd->state.lr_flag != 2)
sd->def_rate += val;
break;
case SP_DEF2_RATE:
if(sd->state.lr_flag != 2)
sd->def2_rate += val;
break;
case SP_MDEF_RATE:
if(sd->state.lr_flag != 2)
sd->mdef_rate += val;
break;
case SP_MDEF2_RATE:
if(sd->state.lr_flag != 2)
sd->mdef2_rate += val;
break;
case SP_RESTART_FULL_RECOVER:
if(sd->state.lr_flag != 2)
sd->special_state.restart_full_recover = 1;
break;
case SP_NO_CASTCANCEL:
if(sd->state.lr_flag != 2)
sd->special_state.no_castcancel = 1;
break;
case SP_NO_CASTCANCEL2:
if(sd->state.lr_flag != 2)
sd->special_state.no_castcancel2 = 1;
break;
case SP_NO_SIZEFIX:
if(sd->state.lr_flag != 2)
sd->special_state.no_sizefix = 1;
break;
case SP_NO_MAGIC_DAMAGE:
if(sd->state.lr_flag == 2)
break;
val+= sd->special_state.no_magic_damage;
sd->special_state.no_magic_damage = cap_value(val,0,100);
break;
case SP_NO_WEAPON_DAMAGE:
if(sd->state.lr_flag == 2)
break;
val+= sd->special_state.no_weapon_damage;
sd->special_state.no_weapon_damage = cap_value(val,0,100);
break;
case SP_NO_MISC_DAMAGE:
if(sd->state.lr_flag == 2)
break;
val+= sd->special_state.no_misc_damage;
sd->special_state.no_misc_damage = cap_value(val,0,100);
break;
case SP_NO_GEMSTONE:
if(sd->state.lr_flag != 2 && sd->special_state.no_gemstone != 2)
sd->special_state.no_gemstone = 1;
break;
case SP_INTRAVISION: // Maya Purple Card effect allowing to see Hiding/Cloaking people [DracoRPG]
if(sd->state.lr_flag != 2) {
sd->special_state.intravision = 1;
clif_status_load(&sd->bl, EFST_CLAIRVOYANCE, 1);
}
break;
case SP_NO_KNOCKBACK:
if(sd->state.lr_flag != 2)
sd->special_state.no_knockback = 1;
break;
case SP_SPLASH_RANGE:
if(sd->bonus.splash_range < val)
sd->bonus.splash_range = val;
break;
case SP_SPLASH_ADD_RANGE:
sd->bonus.splash_add_range += val;
break;
case SP_SHORT_WEAPON_DAMAGE_RETURN:
if(sd->state.lr_flag != 2)
sd->bonus.short_weapon_damage_return += val;
break;
case SP_LONG_WEAPON_DAMAGE_RETURN:
if(sd->state.lr_flag != 2)
sd->bonus.long_weapon_damage_return += val;
break;
case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
if(sd->state.lr_flag != 2)
sd->bonus.magic_damage_return += val;
break;
case SP_ALL_STATS: // [Valaris]
if(sd->state.lr_flag!=2) {
sd->param_bonus[SP_STR-SP_STR]+=val;
sd->param_bonus[SP_AGI-SP_STR]+=val;
sd->param_bonus[SP_VIT-SP_STR]+=val;
sd->param_bonus[SP_INT-SP_STR]+=val;
sd->param_bonus[SP_DEX-SP_STR]+=val;
sd->param_bonus[SP_LUK-SP_STR]+=val;
}
break;
case SP_AGI_VIT: // [Valaris]
if(sd->state.lr_flag!=2) {
sd->param_bonus[SP_AGI-SP_STR]+=val;
sd->param_bonus[SP_VIT-SP_STR]+=val;
}
break;
case SP_AGI_DEX_STR: // [Valaris]
if(sd->state.lr_flag!=2) {
sd->param_bonus[SP_AGI-SP_STR]+=val;
sd->param_bonus[SP_DEX-SP_STR]+=val;
sd->param_bonus[SP_STR-SP_STR]+=val;
}
break;
case SP_PERFECT_HIDE: // [Valaris]
if(sd->state.lr_flag!=2)
sd->special_state.perfect_hiding=1;
break;
case SP_UNBREAKABLE:
if(sd->state.lr_flag!=2)
sd->bonus.unbreakable += val;
break;
case SP_UNBREAKABLE_WEAPON:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_WEAPON;
break;
case SP_UNBREAKABLE_ARMOR:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_ARMOR;
break;
case SP_UNBREAKABLE_HELM:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_HELM;
break;
case SP_UNBREAKABLE_SHIELD:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_SHIELD;
break;
case SP_UNBREAKABLE_GARMENT:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_GARMENT;
break;
case SP_UNBREAKABLE_SHOES:
if(sd->state.lr_flag != 2)
sd->bonus.unbreakable_equip |= EQP_SHOES;
break;
case SP_CLASSCHANGE: // [Valaris]
if(sd->state.lr_flag !=2)
sd->bonus.classchange=val;
break;
case SP_LONG_ATK_RATE:
if(sd->state.lr_flag != 2) //[Lupus] it should stack, too. As any other cards rate bonuses
sd->bonus.long_attack_atk_rate+=val;
break;
case SP_BREAK_WEAPON_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.break_weapon_rate+=val;
break;
case SP_BREAK_ARMOR_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.break_armor_rate+=val;
break;
case SP_ADD_STEAL_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.add_steal_rate+=val;
break;
case SP_DELAYRATE:
if(sd->state.lr_flag != 2)
sd->delayrate+=val;
break;
case SP_CRIT_ATK_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.crit_atk_rate += val;
break;
case SP_NO_REGEN:
if(sd->state.lr_flag != 2)
sd->regen.state.block|=val;
break;
case SP_UNSTRIPABLE_WEAPON:
if(sd->state.lr_flag != 2)
sd->bonus.unstripable_equip |= EQP_WEAPON;
break;
case SP_UNSTRIPABLE:
case SP_UNSTRIPABLE_ARMOR:
if(sd->state.lr_flag != 2)
sd->bonus.unstripable_equip |= EQP_ARMOR;
break;
case SP_UNSTRIPABLE_HELM:
if(sd->state.lr_flag != 2)
sd->bonus.unstripable_equip |= EQP_HELM;
break;
case SP_UNSTRIPABLE_SHIELD:
if(sd->state.lr_flag != 2)
sd->bonus.unstripable_equip |= EQP_SHIELD;
break;
case SP_HP_DRAIN_VALUE: // bonus bHPDrainValue,n;
if(!sd->state.lr_flag) {
sd->right_weapon.hp_drain_class[CLASS_NORMAL] += val;
sd->right_weapon.hp_drain_class[CLASS_BOSS] += val;
} else if(sd->state.lr_flag == 1) {
sd->left_weapon.hp_drain_class[CLASS_NORMAL] += val;
sd->left_weapon.hp_drain_class[CLASS_BOSS] += val;
}
break;
case SP_SP_DRAIN_VALUE: // bonus bSPDrainValue,n;
if(!sd->state.lr_flag) {
sd->right_weapon.sp_drain_class[CLASS_NORMAL] += val;
sd->right_weapon.sp_drain_class[CLASS_BOSS] += val;
} else if(sd->state.lr_flag == 1) {
sd->left_weapon.sp_drain_class[CLASS_NORMAL] += val;
sd->left_weapon.sp_drain_class[CLASS_BOSS] += val;
}
break;
case SP_SP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.sp_gain_value += val;
break;
case SP_HP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.hp_gain_value += val;
break;
case SP_LONG_SP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.long_sp_gain_value += val;
case SP_LONG_HP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.long_hp_gain_value += val;
break;
case SP_MAGIC_SP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.magic_sp_gain_value += val;
break;
case SP_MAGIC_HP_GAIN_VALUE:
if(!sd->state.lr_flag)
sd->bonus.magic_hp_gain_value += val;
break;
case SP_ADD_HEAL_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.add_heal_rate += val;
break;
case SP_ADD_HEAL2_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.add_heal2_rate += val;
break;
case SP_ADD_ITEM_HEAL_RATE:
if(sd->state.lr_flag != 2)
sd->bonus.itemhealrate2 += val;
break;
case SP_EMATK:
if(sd->state.lr_flag != 2)
sd->bonus.ematk += val;
break;
#ifdef RENEWAL_CAST
case SP_FIXCASTRATE:
if(sd->state.lr_flag != 2)
sd->bonus.fixcastrate = min(sd->bonus.fixcastrate,val);
break;
case SP_ADD_FIXEDCAST:
if(sd->state.lr_flag != 2)
sd->bonus.add_fixcast += val;
break;
case SP_CASTRATE:
case SP_VARCASTRATE:
if(sd->state.lr_flag != 2)
sd->bonus.varcastrate -= val;
break;
case SP_ADD_VARIABLECAST:
if(sd->state.lr_flag != 2)
sd->bonus.add_varcast += val;
break;
#else
case SP_ADD_FIXEDCAST:
case SP_FIXCASTRATE:
case SP_ADD_VARIABLECAST:
//ShowWarning("pc_bonus: non-RENEWAL_CAST doesn't support this bonus %d.\n", type);
break;
case SP_VARCASTRATE:
case SP_CASTRATE:
if(sd->state.lr_flag != 2)
sd->castrate += val;
break;
#endif
case SP_ADDMAXWEIGHT:
if (sd->state.lr_flag != 2)
sd->add_max_weight += val;
break;
case SP_ABSORB_DMG_MAXHP: // bonus bAbsorbDmgMaxHP,n;
sd->bonus.absorb_dmg_maxhp = max(sd->bonus.absorb_dmg_maxhp, val);
break;
case SP_CRITICAL_RANGEATK: // bonus bCriticalLong,n;
if (sd->state.lr_flag != 2)
sd->bonus.critical_rangeatk += val*10;
else
sd->bonus.arrow_cri += val*10;
break;
case SP_WEAPON_ATK_RATE:
if (sd->state.lr_flag != 2)
sd->bonus.weapon_atk_rate += val;
break;
case SP_WEAPON_MATK_RATE:
if (sd->state.lr_flag != 2)
sd->bonus.weapon_matk_rate += val;
break;
case SP_NO_MADO_FUEL:
if (sd->state.lr_flag != 2)
sd->special_state.no_mado_fuel = 1;
break;
case SP_NO_WALK_DELAY:
if (sd->state.lr_flag != 2)
sd->special_state.no_walk_delay = 1;
break;
default:
if (running_npc_stat_calc_event) {
ShowWarning("pc_bonus: unknown bonus type %d %d in OnPCStatCalcEvent!\n", type, val);
}
else if (current_equip_combo_pos > 0) {
ShowWarning("pc_bonus: unknown bonus type %d %d in a combo with item #%d\n", type, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
}
else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
ShowWarning("pc_bonus: unknown bonus type %d %d in item #%d\n", type, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
}
else {
ShowWarning("pc_bonus: unknown bonus type %d %d in unknown usage. Report this!\n", type, val);
}
break;
}
}
/*==========================================
* Player bonus (type) with args type2 and val, called trough bonus2 (npc)
* format: bonus2 bBonusName,type2,val;
* @param sd
* @param type Bonus type used by bBonusName
* @param type2
* @param val Value that usually for rate or fixed value
*------------------------------------------*/
void pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
{
nullpo_retv(sd);
switch(type){
case SP_ADDELE: // bonus2 bAddEle,e,x;
PC_BONUS_CHK_ELEMENT(type2,SP_ADDELE);
if(!sd->state.lr_flag || sd->state.lr_flag == 3)
sd->right_weapon.addele[type2]+=val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.addele[type2]+=val;
else if(sd->state.lr_flag == 2)
sd->arrow_addele[type2]+=val;
break;
case SP_ADDRACE: // bonus2 bAddRace,r,x;
PC_BONUS_CHK_RACE(type2,SP_ADDRACE);
if(!sd->state.lr_flag || sd->state.lr_flag == 3)
sd->right_weapon.addrace[type2]+=val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.addrace[type2]+=val;
else if(sd->state.lr_flag == 2)
sd->arrow_addrace[type2]+=val;
break;
case SP_ADDCLASS: // bonus2 bAddClass,c,x;
PC_BONUS_CHK_CLASS(type2,SP_ADDCLASS);
if(!sd->state.lr_flag || sd->state.lr_flag == 3)
sd->right_weapon.addclass[type2]+=val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.addclass[type2]+=val;
else if(sd->state.lr_flag == 2)
sd->arrow_addclass[type2]+=val;
break;
case SP_ADDSIZE: // bonus2 bAddSize,s,x;
PC_BONUS_CHK_SIZE(type2,SP_ADDSIZE);
if(!sd->state.lr_flag || sd->state.lr_flag == 3)
sd->right_weapon.addsize[type2]+=val;
else if(sd->state.lr_flag == 1)
sd->left_weapon.addsize[type2]+=val;
else if(sd->state.lr_flag == 2)
sd->arrow_addsize[type2]+=val;
break;
case SP_SUBELE: // bonus2 bSubEle,e,x;
PC_BONUS_CHK_ELEMENT(type2,SP_SUBELE);
if(sd->state.lr_flag != 2)
sd->subele_script[type2] += val;
break;
case SP_SUBRACE: // bonus2 bSubRace,r,x;
PC_BONUS_CHK_RACE(type2,SP_SUBRACE);
if(sd->state.lr_flag != 2)
sd->subrace[type2]+=val;
break;
case SP_SUBCLASS: // bonus2 bSubClass,c,x;
PC_BONUS_CHK_CLASS(type2,SP_SUBCLASS);
if(sd->state.lr_flag != 2)
sd->subclass[type2]+=val;
break;
case SP_ADDEFF: // bonus2 bAddEff,eff,n;
PC_BONUS_CHK_SC(type2,SP_ADDEFF);
pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, 0, 0);
break;
case SP_ADDEFF2: // bonus2 bAddEff2,eff,n;
PC_BONUS_CHK_SC(type2,SP_ADDEFF2);
pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, ATF_SELF, 0);
break;
case SP_RESEFF: // bonus2 bResEff,eff,n;
if(sd->state.lr_flag == 2)
break;
if (sd->reseff.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus2: SP_RESEFF: Reached max (%d) number of resistance bonuses per character!\n", MAX_PC_BONUS);
break;
}
pc_bonus_itembonus(sd->reseff, type2, val, true);
break;
case SP_MAGIC_ADDELE: // bonus2 bMagicAddEle,e,x;
PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ADDELE);
if(sd->state.lr_flag != 2)
sd->magic_addele_script[type2] += val;
break;
case SP_MAGIC_ADDRACE: // bonus2 bMagicAddRace,r,x;
PC_BONUS_CHK_RACE(type2,SP_MAGIC_ADDRACE);
if(sd->state.lr_flag != 2)
sd->magic_addrace[type2]+=val;
break;
case SP_MAGIC_ADDCLASS: // bonus2 bMagicAddClass,c,x;
PC_BONUS_CHK_CLASS(type2,SP_MAGIC_ADDCLASS);
if(sd->state.lr_flag != 2)
sd->magic_addclass[type2]+=val;
break;
case SP_MAGIC_ADDSIZE: // bonus2 bMagicAddSize,s,x;
PC_BONUS_CHK_SIZE(type2,SP_MAGIC_ADDSIZE);
if(sd->state.lr_flag != 2)
sd->magic_addsize[type2]+=val;
break;
case SP_MAGIC_ATK_ELE: // bonus2 bMagicAtkEle,e,x;
PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ATK_ELE);
if(sd->state.lr_flag != 2)
sd->magic_atk_ele[type2]+=val;
break;
case SP_ADD_DAMAGE_CLASS: { // bonus2 bAddDamageClass,mid,x;
struct weapon_data *wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
if (wd->add_dmg.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus2: SP_ADD_DAMAGE_CLASS: Reached max (%d) number of add class damage bonuses per character!\n", MAX_PC_BONUS);
break;
}
pc_bonus_itembonus(wd->add_dmg, type2, val, false);
}
break;
case SP_ADD_MAGIC_DAMAGE_CLASS: // bonus2 bAddMagicDamageClass,mid,x;
if(sd->state.lr_flag == 2)
break;
if (sd->add_mdmg.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus2: SP_ADD_MAGIC_DAMAGE_CLASS: Reached max (%d) number of add class magic dmg bonuses per character!\n", MAX_PC_BONUS);
break;
}
pc_bonus_itembonus(sd->add_mdmg, type2, val, false);
break;
case SP_ADD_DEF_MONSTER: // bonus2 bAddDefMonster,mid,x;
if(sd->state.lr_flag == 2)
break;
if (sd->add_def.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus2: SP_ADD_DEF_MONSTER: Reached max (%d) number of add class def bonuses per character!\n", MAX_PC_BONUS);
break;
}
pc_bonus_itembonus(sd->add_def, type2, val, false);
break;
case SP_ADD_MDEF_MONSTER: // bonus2 bAddMDefMonster,mid,x;
if(sd->state.lr_flag == 2)
break;
if (sd->add_mdef.size() == MAX_PC_BONUS) {
ShowWarning("pc_bonus2: SP_ADD_MDEF_MONSTER: Reached max (%d) number of add class mdef bonuses per character!\n", MAX_PC_BONUS);
break;
}
pc_bonus_itembonus(sd->add_mdef, type2, val, false);
break;
case SP_HP_DRAIN_RATE: // bonus2 bHPDrainRate,x,n;
if(!sd->state.lr_flag) {
sd->right_weapon.hp_drain_rate.rate += type2;
sd->right_weapon.hp_drain_rate.per += val;
}
else if(sd->state.lr_flag == 1) {
sd->left_weapon.hp_drain_rate.rate += type2;
sd->left_weapon.hp_drain_rate.per += val;
}
break;
case SP_SP_DRAIN_RATE: // bonus2 bSPDrainRate,x,n;
if(!sd->state.lr_flag) {
sd->right_weapon.sp_drain_rate.rate += type2;
sd->right_weapon.sp_drain_rate.per += val;
}
else if(sd->state.lr_flag == 1) {
sd->left_weapon.sp_drain_rate.rate += type2;
sd->left_weapon.sp_drain_rate.per += val;
}
break;
case SP_SP_VANISH_RATE: // bonus2 bSPVanishRate,x,n;
if(sd->state.lr_flag != 2) {
pc_bonus_addvanish(sd->sp_vanish, type2, val, BF_NORMAL);
}
break;
case SP_HP_VANISH_RATE: // bonus2 bHPVanishRate,x,n;
if(sd->state.lr_flag != 2) {
pc_bonus_addvanish(sd->hp_vanish, type2, val, BF_NORMAL);
}
break;
case SP_GET_ZENY_NUM: // bonus2 bGetZenyNum,x,n;
if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) {
sd->bonus.get_zeny_rate = val;
sd->bonus.get_zeny_num = type2;
}
break;
case SP_ADD_GET_ZENY_NUM: // bonus2 bAddGetZenyNum,x,n;
if(sd->state.lr_flag != 2) {
sd->bonus.get_zeny_rate += val;
sd->bonus.get_zeny_num += type2;
}
break;
case SP_WEAPON_COMA_ELE: // bonus2 bWeaponComaEle,e,n;
PC_BONUS_CHK_ELEMENT(type2,SP_WEAPON_COMA_ELE);
if(sd->state.lr_flag == 2)
break;
sd->weapon_coma_ele[type2] += val;
sd->special_state.bonus_coma = 1;
break;
case SP_WEAPON_COMA_RACE: // bonus2 bWeaponComaRace,r,n;
PC_BONUS_CHK_RACE(type2,SP_WEAPON_COMA_RACE);
if(sd->state.lr_flag == 2)
break;
sd->weapon_coma_race[type2] += val;
sd->special_state.bonus_coma = 1;
break;