Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'Item'
- require 'Armor'
- require 'Weapon'
- require 'Wallet'
- require 'mysql2'
- $CONFIG['SQL_HOST'] = "photons.no-ip.org"
- $CONFIG['SQL_USER'] = "terras"
- $CONFIG['SQL_PASS'] = ""
- $CONFIG['SQL_DB'] = "terras"
- class Player
- attr_accessor :id
- attr_accessor :owner_name
- attr_accessor :player_name
- # Player header
- attr_accessor :player_class
- attr_accessor :player_race
- attr_accessor :player_alignment
- attr_accessor :player_god
- # Vital stats
- attr_accessor :level
- attr_accessor :max_hp
- attr_accessor :current_hp
- # Player's physical attributes
- attr_accessor :gender
- attr_accessor :height
- attr_accessor :weight
- attr_accessor :eye_color
- attr_accessor :hair
- attr_accessor :body_type
- attr_accessor :apparent_age
- attr_accessor :actual_age
- attr_accessor :max_age
- # Player experience
- attr_accessor :earned_xp
- attr_accessor :needed_xp
- attr_accessor :story_points
- # Strength stats
- attr_accessor :strength
- attr_accessor :stamina
- attr_accessor :muscle
- attr_accessor :endurance
- attr_accessor :power
- attr_accessor :carry_weight
- attr_accessor :damage
- attr_accessor :hit
- attr_accessor :max_exertion
- attr_accessor :max_press
- attr_accessor :resist_exertion
- attr_accessor :resist_grapple
- # Dexterity stats
- attr_accessor :dexterity
- attr_accessor :accuracy
- attr_accessor :balance
- attr_accessor :aim
- attr_accessor :evasion
- attr_accessor :missile_hit_bonus
- attr_accessor :defense_value
- attr_accessor :bonus_attacks
- attr_accessor :base_initiative
- attr_accessor :resist_distraction
- attr_accessor :chance_dodge
- # Constitution stats
- attr_accessor :constitution
- attr_accessor :health
- attr_accessor :fitness
- attr_accessor :shock
- attr_accessor :survival
- attr_accessor :regeneration_rate
- attr_accessor :hit_point_modifier
- attr_accessor :rest_adjust
- attr_accessor :mph_modifier
- attr_accessor :resist_disease
- attr_accessor :resist_toxins
- # Intelligence stats
- attr_accessor :intelligence
- attr_accessor :reason
- attr_accessor :knowledge
- attr_accessor :learn
- attr_accessor :recall
- attr_accessor :max_spell_level
- attr_accessor :bonus_skills
- attr_accessor :base_mana
- attr_accessor :ask_dm_any_question
- attr_accessor :resist_trickery
- attr_accessor :resist_spell
- # Wisdom stats
- attr_accessor :wisdom
- attr_accessor :intuition
- attr_accessor :willpower
- attr_accessor :perception
- attr_accessor :force_of_will
- attr_accessor :spirit_multiplier
- attr_accessor :number_of_artifacts
- attr_accessor :enlightenment
- attr_accessor :artifact_bonus
- attr_accessor :resist_surprise
- attr_accessor :resist_psychic
- # Charisma stats
- attr_accessor :charisma
- attr_accessor :leadership
- attr_accessor :appearance
- attr_accessor :inspiration
- attr_accessor :persuasion
- attr_accessor :max_number_of_minions
- attr_accessor :comeliness
- attr_accessor :number_of_minions
- attr_accessor :comely_scale
- attr_accessor :resist_disloyalty
- attr_accessor :resist_prejudice
- # Rogue skills
- attr_accessor :pick_pockets
- attr_accessor :open_locks
- attr_accessor :make_locks
- attr_accessor :find_traps
- attr_accessor :move_silently
- attr_accessor :hide_in_shadows
- attr_accessor :climb_walls
- attr_accessor :detect_noise
- attr_accessor :detect_magic
- attr_accessor :read_languages
- attr_accessor :bribe
- attr_accessor :slip_bonus
- attr_accessor :backstab_multiplier
- # Contains a wallet object
- attr_accessor :wallet
- # Inventory
- attr_accessor :inventory
- attr_accessor :owned_weapons
- attr_accessor :owned_armor
- def initialize
- end
- def load_existing_player(player_id)
- end
- def create_new_player(character_name, character_class, character_race, owner_name)
- # Set the main variables based on creation parameters.
- @owner_name = owner_name
- @player_name = character_name
- @player_class = character_class
- @player_race = character_race
- # Set the default vital stats.
- @level = 1
- @max_hp = get_max_hitpoints
- @current_hp = @max_hp
- # Set the vanity variables to default values.
- @player_alignment = "Neutral"
- @player_god = "Agnostic"
- @gender = "Unknown"
- @height = "Unknown"
- @weight = 180
- @eye_color = "Unknown"
- @hair = "Unknown"
- @body_type = "Unknown"
- @apparent_age = 20
- @actual_age = 20
- @max_age = 80
- # Set experience variables to default values.
- @earned_xp = 0
- @needed_xp = get_xp_needed_for_next_level
- @story_points = 0
- # Roll the player's primary stats (ie: Strength, Dexterity, etc.).
- roll_primary_stats
- # Calculates and sets the player's secondary stats.
- set_secondary_stats
- # Calculates and sets the player's rogue skills.
- set_rogue_skills
- # Creates the player's wallet.
- @wallet = Wallet.new
- # Creates the player's inventory.
- @inventory = []
- @owned_armor = []
- @owned_weapons = []
- end
- # Returns the XP needed to level up.
- def get_xp_needed_for_next_level
- return 1800 # PLACEHOLDER
- end
- # Calculate the maximum number of hitpoints.
- def get_max_hitpoints
- return 17 # PLACEHOLDER
- end
- # Rolls and sets the player's primary stats.
- def roll_primary_stats
- @strength = 1 + rand(20)
- @dexterity = 1 + rand(20)
- @constitution = 1 + rand(20)
- @intelligence = 1 + rand(20)
- @wisdom = 1 + rand(20)
- @charisma = 1 + rand(20)
- end
- # Calculates and sets the player's secondary stats.
- def set_secondary_stats
- # Strength stats
- @stamina = @strength
- @muscle = @strength
- @endurance = 0.35 # PLACEHOLDER
- @power = 0.50 # PLACEHOLDER
- @carry_weight = 235 # PLACEHOLDER
- @damage = 5 # PLACEHOLDER
- @hit = 2 # PLACEHOLDER
- @max_exertion = 4.5 # PLACEHOLDER
- @max_press = 640 # PLACEHOLDER
- @resist_exertion = @strength # PLACEHOLDER
- @resist_grapple = @strength # PLACEHOLDER
- # Dexterity stats
- @accuracy = @dexterity
- @balance = @dexterity
- @aim = 0.35 # PLACEHOLDER
- @evasion = 0.60 # PLACEHOLDER
- @missile_hit_bonus = 1 # PLACEHOLDER
- @defense_value = 2 # PLACEHOLDER
- @bonus_attacks = 1.10 # PLACEHOLDER
- @base_initiative = 12 # PLACEHOLDER
- @resist_distraction = @dexterity # PLACEHOLDER
- @chance_dodge = @dexterity # PLACEHOLDER
- # Constitution stats
- @health = @constitution
- @fitness = @constitution
- @shock = 0.50 # PLACEHOLDER
- @survival = 0.65 # PLACEHOLDER
- @regeneration_rate = 4 # PLACEHOLDER
- @hit_point_modifier = 3 # PLACEHOLDER
- @rest_adjust = 0.85 # PLACEHOLDER
- @mph_modifier = 3 # PLACEHOLDER
- @resist_disease = @constituion # PLACEHOLDER
- @resist_toxins = @constituion # PLACEHOLDER
- # Intelligence stats
- @reason = @intelligence
- @knowledge = @intelligence
- @learn = 0.40 # PLACEHOLDER
- @recall = 0.60 # PLACEHOLDER
- @max_spell_level = 6 # PLACEHOLDER
- @bonus_skills = 6 # PLACEHOLDER
- @base_mana = 8 # PLACEHOLDER
- @ask_dm_any_question = 1 # PLACEHOLDER
- @resist_trickery = @intelligence # PLACEHOLDER
- @resist_spell = @intelligence # PLACEHOLDER
- # Wisdom stats
- @intuition = @wisdom
- @willpower = @wisdom
- @perception = 0.30 # PLACEHOLDER
- @force_of_will = 0.40 # PLACEHOLDER
- @spirit_multiplier = 3 # PLACEHOLDER
- @number_of_artifacts = 5 # PLACEHOLDER
- @enlightenment = "None" # PLACEHOLDER
- @artifact_bonus = 1 # PLACEHOLDER
- @resist_surprise = @wisdom # PLACEHOLDER
- @resist_psychic = @wisdom # PLACEHOLDER
- # Charisma stats
- @leadership = @charisma
- @appearance = @charisma
- @inspiration = 0.40 # PLACEHOLDER
- @persuasion = 0.25 # PLACEHOLDER
- @max_number_of_minions = 30 # PLACEHOLDER
- @comeliness = "Fine" # PLACEHOLDER
- @number_of_minions = 0 # PLACEHOLDER
- @comely_scale = 0 # PLACEHOLDER
- @resist_disloyalty = @charisma # PLACEHOLDER
- @resist_prejudice = @charisma # PLACEHOLDER
- end
- # Calculates and sets the player's rogue skills.
- def set_rogue_skills
- @pick_pockets = 0.20 # PLACEHOLDER
- @open_locks = 0.10 # PLACEHOLDER
- @make_locks = 0.10 # PLACEHOLDER
- @find_traps = 0.15 # PLACEHOLDER
- @move_silently = 0.20 # PLACEHOLDER
- @hide_in_shadows = 0.10 # PLACEHOLDER
- @climb_walls = 0.50 # PLACEHOLDER
- @detect_noise = 0.25 # PLACEHOLDER
- @detect_magic = 0.15 # PLACEHOLDER
- @read_languages = 0.10 # PLACEHOLDER
- @bribe = 0.10 # PLACEHOLDER
- @slip_bonus = 0.10 # PLACEHOLDER
- @backstab_multiplier = 2 # PLACEHOLDER
- end
- # Saves the player's state to the SQL database.
- def save_player_to_database
- begin
- # Connect to the MySQL database.
- sql = Mysql2::Client.new(:host => $CONFIG['SQL_HOST'], :username => $CONFIG['SQL_USER'], :password => $CONFIG['SQL_PASS'], :database => $CONFIG['SQL_DB'])
- # Determine if the player already exists in the database.
- query = "SELECT id FROM #{$CONFIG['SQL_DB']}.Players WHERE player_name = '#{@player_name}';"
- result = sql.query(query)
- if result.count == 0
- # Player isn't in the database yet.
- # Save new player stats to database.
- begin
- query = "INSERT INTO #{$CONFIG['SQL_DB']}.Players ("\
- "owner_name, player_name, player_class, player_race, "\
- "player_alignment, player_god, level, max_hp, current_hp, "\
- "gender, height, weight, eye_color, hair, body_type, apparent_age, "\
- "actual_age, max_age, earned_xp, needed_xp, story_points, strength, "\
- "stamina, muscle, endurance, power, carry_weight, damage, hit, max_exertion, "\
- "max_press, resist_exertion, resist_grapple, dexterity, accuracy, balance, "\
- "aim, evasion, missile_hit_bonus, defense_value, bonus_attacks, base_initiative, "\
- "resist_distraction, chance_dodge, constitution, health, fitness, shock, survival, "\
- "regeneration_rate, hit_point_modifier, rest_adjust, mph_modifier, resist_disease, "\
- "resist_toxins, intelligence, reason, knowledge, learn, recall, max_spell_level, "\
- "bonus_skills, base_mana, ask_dm_any_question, resist_trickery, resist_spell, "\
- "wisdom, intuition, willpower, perception, force_of_will, spirit_multiplier, "\
- "number_of_artifacts, enlightenment, artifact_bonus, resist_surprise, resist_psychic, "\
- "charisma, leadership, appearance, inspiration, persuasion, max_number_of_minions, "\
- "comeliness, number_of_minions, comely_scale, resist_disloyalty, resist_prejudice, "\
- "pick_pockets, open_locks, make_locks, find_traps, move_silently, hide_in_shadows, "\
- "climb_walls, detect_noise, detect_magic, read_languages, bribe, slip_bonus, "\
- "backstab_multiplier) VALUES ('#{@owner_name}', '#{@player_name}', '#{@player_class}', "\
- "'#{@player_race}', '#{@player_alignment}', '#{@player_god}', #{@level}, #{@max_hp}, "\
- "#{@current_hp}, '#{@gender}', '#{@height}', #{@weight}, '#{@eye_color}', '#{@hair}', "\
- "'#{@body_type}', #{@apparent_age}, #{@actual_age}, #{@max_age}, #{@earned_xp}, "\
- "#{@needed_xp}, #{@story_points}, #{@strength}, #{@stamina}, #{@muscle}, #{@endurance}, "\
- "#{@power}, #{@carry_weight}, #{@damage}, #{@hit}, #{@max_exertion}, #{@max_press}, "\
- "#{@resist_exertion}, #{@resist_grapple}, #{@dexterity}, #{@accuracy}, #{@balance}, "\
- "#{@aim}, #{@evasion}, #{@missile_hit_bonus}, #{@defense_value}, #{@bonus_attacks}, "\
- "#{@base_initiative}, #{@resist_distraction}, #{@chance_dodge}, #{@constitution}, "\
- "#{@health}, #{@fitness}, #{@shock}, #{@survival}, #{@regeneration_rate}, "\
- "#{@hit_point_modifier}, #{@rest_adjust}, #{@mph_modifier}, #{@resist_disease}, "\
- "#{@resist_toxins}, #{@intelligence}, #{@reason}, #{@knowledge}, #{@learn}, #{@recall}, "\
- "#{@max_spell_level}, #{@bonus_skills}, #{@base_mana}, #{@ask_dm_any_question}, "\
- "#{@resist_trickery}, #{@resist_spell}, #{@wisdom}, #{@intuition}, #{@willpower}, "\
- "#{@perception}, #{@force_of_will}, #{@spirit_multiplier}, #{@number_of_artifacts}, "\
- "#{@enlightenment}, #{@artifact_bonus}, #{@resist_surprise}, #{@resist_psychic}, "\
- "#{@charisma}, #{@leadership}, #{@appearance}, #{@inspiration}, #{@persuasion}, "\
- "#{@max_number_of_minions}, #{@comeliness}, #{@number_of_minions}, #{@comely_scale}, "\
- "#{@resist_disloyalty}, #{@resist_prejudice}, #{@pick_pockets}, #{@open_locks}, "\
- "#{@make_locks}, #{@find_traps}, #{@move_silently}, #{@hide_in_shadows}, #{@climb_walls}, "\
- "#{@detect_noise}, #{@detect_magic}, #{@read_languages}, #{@bribe}, #{@slip_bonus}, "\
- "#{@backstab_multiplier});"
- sql.query(query)
- sql.query("COMMIT")
- # Get the player's ID from the database.
- query = "SELECT id FROM #{$CONFIG['SQL_DB']}.Players WHERE player_name='#{@player_name}';"
- @id = sql.query(query).fetch_hash()['id']
- # Create the player's Wallet.
- query = "INSERT INTO #{$CONFIG['SQL_DB']}.Wallets (player_id) VALUES (#{@id});"
- sql.query("COMMIT")
- rescue => e
- puts "Unable to write Player data to database!"
- raise e
- end
- else
- # Player is already in the database.
- # Get the player's ID from the database query result.
- @id = result.fetch_hash()['id']
- # Update Players table with the current player's state.
- query = "UPDATE #{$CONFIG['SQL_DB']}.Players SET owner_name='#{@owner_name}', "\
- "player_name='#{@player_name}', player_class='#{@player_class}', "\
- "player_race='#{@player_race}', player_alignment='#{@player_alignment}', "\
- "player_god='#{@player_god}, level=#{@level}, max_hp=#{@max_hp}, "\
- "current_hp=#{@current_hp}, gender='#{@gender}', height='#{@height}', "\
- "weight=#{@weight}, eye_color='#{@eye_color}', hair='#{@hair}', "\
- "body_type='#{@body_type}', apparent_age=#{@apparent_age}, "\
- "actual_age=#{@actual_age}, max_age=#{@max_age}, earned_xp=#{@earned_xp}, "\
- "needed_xp=#{@needed_xp}, story_points=#{@story_points}, strength=#{@strength}, "\
- "stamina=#{@stamina}, muscle=#{@muscle}, endurance=#{@endurance}, power=#{@power}, "\
- "carry_weight=#{@carry_weight}, damage=#{@damage}, hit=#{@hit}, "\
- "max_exertion=#{@max_exertion}, max_press=#{@max_press}, "\
- "resist_exertion=#{@resist_exertion}, resist_grapple=#{@resist_grapple}, "\
- "dexterity=#{@dexterity}, accuracy=#{@accuracy}, balance=#{@balance}, "\
- "aim=#{@aim}, evasion=#{@evasion}, missile_hit_bonus=#{@missile_hit_bonus}, "\
- "defense_value=#{@defense_value}, bonus_attacks=#{@bonus_attacks}, "\
- "base_initiative=#{@base_initiative}, resist_distraction=#{@resist_distraction}, "\
- "chance_dodge=#{@chance_dodge}, constitution=#{@constitution}, health=#{@health}, "\
- "fitness=#{@fitness}, shock=#{@shock}, survival=#{@survival}, "\
- "regeneration_rate=#{@regeneration_rate}, hit_point_modifier=#{@hit_point_modifier}, "\
- "rest_adjust=#{@rest_adjust}, mph_modifier=#{@mph_modifier}, "\
- "resist_disease=#{@resist_disease}, resist_toxins=#{@resist_toxins}, "\
- "intelligence=#{@intelligence}, reason=#{@reason}, knowledge=#{@knowledge}, "\
- "learn=#{@learn}, recall=#{@recall}, max_spell_level=#{@max_spell_level}, "\
- "bonus_skills=#{@bonus_skills}, base_mana=#{@base_mana}, "\
- "ask_dm_any_question=#{@ask_dm_any_question}, resist_trickery=#{@resist_trickery}, "\
- "resist_spell=#{@resist_spell}, wisdom=#{@wisdom}, intuition=#{@intuition}, "\
- "willpower=#{@willpower}, perception=#{@perception}, force_of_will=#{@force_of_will}, "\
- "spirit_multiplier=#{@spirit_multiplier}, number_of_artifacts=#{@number_of_artifacts}, "\
- "enlightenment=#{@enlightenment}, artifact_bonus=#{@artifact_bonus}, "\
- "resist_surprise=#{@resist_surprise}, resist_psychic=#{@resist_psychic}, "\
- "charisma=#{@charisma}, leadership=#{@leadership}, appearance=#{@appearance}, "\
- "inspiration=#{@inspiration}, persuasion=#{@persuasion}, "\
- "max_number_of_minions=#{@max_number_of_minions}, comeliness=#{@comeliness}, "\
- "number_of_minions=#{@number_of_minions}, comely_scale=#{@comely_scale}, "\
- "resist_disloyalty=#{@resist_disloyalty}, resist_prejudice=#{@resist_prejudice}, "\
- "pick_pockets=#{@pick_pockets}, open_locks=#{@open_locks}, make_locks=#{@make_locks}, "\
- "find_traps=#{@find_traps}, move_silently=#{@move_silently}, "\
- "hide_in_shadows=#{@hide_in_shadows}, climb_walls=#{@climb_walls}, "\
- "detect_noise=#{@detect_noise}, detect_magic=#{@detect_magic}, "\
- "read_languages=#{@read_languages}, bribe=#{@bribe}, slip_bonus=#{@slip_bonus}, "\
- "backstab_multiplier=#{@backstab_multiplier} WHERE id=#{@id};"
- sql.query(query)
- sql.query("COMMIT")
- # Save the player's Wallet.
- query = "UPDATE #{$CONFIG['SQL_DB']}.Wallets SET copper=#{@wallet.copper}, silver=#{@wallet.silver}, "\
- "gold=#{@wallet.gold}, platinum=#{@wallet.platinum}, celestium=#{@wallet.celestium}, "\
- "gems=#{@wallet.gems}, bank=#{@wallet.bank}, credit=#{@wallet.credit} "\
- "WHERE player_id=#{@id};"
- sql.query(query)
- sql.query("COMMIT")
- ###################################################
- ###################################################
- ###################################################
- # Save the player's owned armor.
- query = "SELECT * FROM #{$CONFIG['SQL_DB']}.Owned_Armor;"
- result = sql.query(query)
- result.each do |row|
- @owned_armor.each do |armor|
- end
- end
- ###################################################
- ###################################################
- ###################################################
- end
- rescue => e
- raise e
- ensure
- sql.close if sql
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement