[XP] Luck

Started by Falcon, September 07, 2008, 12:24:19 pm

Previous topic - Next topic

Falcon

September 07, 2008, 12:24:19 pm Last Edit: February 21, 2009, 05:57:35 am by Blizzard
Luck
Authors: Falcon
Version: 1.0
Type: Actor/Battle Add-on
Key Term: Misc System



Introduction

This Script allows each actor to have luck, a hidden stat which affect critical hit chance, item gained chance, and gold gained chance.


Features


  • The party's average luck effects the percent of getting an item in battle
  • The party's average luck effects the amount of gold gained in battle
  • Each actor's luck effects their critical hit chance



Demo

http://www.mediafire.com/?32b2dylwemj


Script
http://falcon.rmrk.net/luck.txt
Spoiler: ShowHide
#==============================================================================
# Luck Script 1.0
#------------------------------------------------------------------------------
# By The_Falcon
#==============================================================================

#==============================================================================
# Instructions
#------------------------------------------------------------------------------
# To use this script, go down to line 64 and define each actor's luck
# Luck can also be altered in game with the following call script command:
# $game_actors[X].luck = Y
# With X being the actor id number and Y beeing the luck value.
# It's worth noting you can have unlucky characters by assign a negative value
#==============================================================================

#==============================================================================
# The following default methods are rewritten:
# Scene_Battle : start_phase5
# Game_Battler : attack_effect
#------------------------------------------------------------------------------
# The following default methods are aliased
# Scene_Title  : command_new_game
#==============================================================================

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
attr_reader   :luck # luck
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias luckinitialize initialize
  def initialize
luckinitialize
@luck = 0
  end
  #--------------------------------------------------------------------------
  # * Change Luck
  # newluck : new luck
  #--------------------------------------------------------------------------
  def luck=(newluck)
# Change luck
@luck = newluck
  end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================

class Scene_Title
  alias new_game_luck command_new_game
  def command_new_game
new_game_luck
#==============================================================================
# Set the actor's luck here!
#==============================================================================
$game_actors[1].luck = 50
$game_actors[2].luck = 30
$game_actors[3].luck = -30
$game_actors[4].luck = 10
$game_actors[5].luck = 30
$game_actors[6].luck = 40
$game_actors[7].luck = 100
$game_actors[8].luck = 70
#==============================================================================
  end
end
#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  def start_phase5
# Shift to phase 5
@phase = 5
# Play battle end ME
$game_system.me_play($game_system.battle_end_me)
# Return to BGM before battle started
$game_system.bgm_play($game_temp.map_bgm)
# Initialize EXP, amount of gold, and treasure
exp = 0
gold = 0
treasures = []
# Initialize the variable while the party's combined luck will be stored
partyluck = 0
# Calculate the party's combined luck
for i in 0...$game_party.actors.size
  partyluckold = partyluck
  partyluck = $game_party.actors[i].luck + partyluckold
end
# Loop
for enemy in $game_troop.enemies
  # If enemy is not hidden
  unless enemy.hidden
# Add EXP and amount of gold obtained
exp += enemy.exp
gold += enemy.gold
# Increase/decrease the chance of getting an item based on luck
random = (rand(100) - (Integer(Float(partyluck/$game_party.actors.size))/10))
# Determine if treasure appears
if random < enemy.treasure_prob
  if enemy.item_id > 0
treasures.push($data_items[enemy.item_id])
  end
  if enemy.weapon_id > 0
treasures.push($data_weapons[enemy.weapon_id])
  end
  if enemy.armor_id > 0
treasures.push($data_armors[enemy.armor_id])
  end
end
  end
end
# Treasure is limited to a maximum of 6 items
treasures = treasures[0..5]
# Obtaining EXP
for i in 0...$game_party.actors.size
  actor = $game_party.actors[i]
  if actor.cant_get_exp? == false
last_level = actor.level
actor.exp += ((exp * $game_party.actors[i].luck/10) + exp)
if actor.level > last_level
  @status_window.level_up(i)
end
  end
end
# Calculate the extra gold the party will recieve
extragold = Integer(gold * ((Float(partyluck/$game_party.actors.size))/1000))
# Obtaining gold
$game_party.gain_gold(extragold + gold)
# Obtaining treasure
for item in treasures
  case item
  when RPG::Item
$game_party.gain_item(item.id, 1)
  when RPG::Weapon
$game_party.gain_weapon(item.id, 1)
  when RPG::Armor
$game_party.gain_armor(item.id, 1)
  end
end
# Make battle result window
@result_window = Window_BattleResult.new(exp, extragold + gold, treasures)
# Set wait count
@phase5_wait_count = 100
  end
end
#==============================================================================
# ** Game_Battler (part 3)
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================
class Game_Battler 
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  # attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
  # Calculate basic damage
  atk = [attacker.atk - self.pdef / 2, 0].max
  self.damage = atk * (20 + attacker.str) / 20
  # Element correction
  self.damage *= elements_correct(attacker.element_set)
  self.damage /= 100
  # If damage value is strictly positive
  if self.damage > 0
# Critical correction
random = (rand(100) - (Integer(attacker.luck/10)))
if random < 4 * attacker.dex / self.agi
  self.damage *= 2
  self.critical = true
end
# Guard correction
if self.guarding?
  self.damage /= 2
end
  end
  # Dispersion
  if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
  end
  # Second hit detection
  eva = 8 * self.agi / attacker.dex + self.eva
  hit = self.damage < 0 ? 100 : 100 - eva
  hit = self.cant_evade? ? 100 : hit
  hit_result = (rand(100) < hit)
end
# If hit occurs
if hit_result == true
  # State Removed by Shock
  remove_states_shock
  # Substract damage from HP
  self.hp -= self.damage
  # State change
  @state_changed = false
  states_plus(attacker.plus_state_set)
  states_minus(attacker.minus_state_set)
# When missing
else
  # Set damage to "Miss"
  self.damage = "Miss"
  # Clear critical flag
  self.critical = false
end
# End Method
return true
  end
end



Instructions

As long as you've defined the actor's luck around line 64, put this above main, below the default scripts, and it should work fine.


Compatibility

Probably incompatible with SDK and most other Battle Systems, I rewrite too many methods.


Credits and Thanks

Give credit to Falcon.
Thanks to DragoonNouman and Ancient Algebra for the testing.


shdwlink1993

Databased. Nice script, Falcon.

In case anyone wonders, the first post was modified because of something stupid I did while moving it... Sorry...
Stuff I've made:




"Never think you're perfect or else you'll stop improving yourself."

"Some people say the glass is half full... some half empty... I just wanna know who's been drinking my beer."

Blizzard

Nice. ^_^

Hm, I'm just not sure about the Key Term. Would you say that "Actor Add-on" might be more suitable? But it IS a misc system after... IDK, what do you think?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Falcon

While it adds the variable to the actor class, the luck only factors in battle. So it really would go in neither.

Blizzard

September 09, 2008, 09:06:06 am #4 Last Edit: September 09, 2008, 09:08:30 am by Blizzard
Let's leave it as misc system then since it has more to do with the battle. But then it could be a "Battle Add-on". :O.o:
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Falcon

Ah, but the gold from battle affects the party :D

Blizzard

Let's leave it a Misc System then. :xD:
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.