Jump to content
Rpg²S Forum

*Threat System


SIMO696
 Share

Recommended Posts

Threat System

Descrizione


Script grazie al quale i mostri non attaccano piu' a caso;bensi' attaccano secondo un livello di minaccia che aumenta quando un pg attacca e diminuisce quando un pg si difende.


Autore

 

Fantasist
con come al solito la mia traduzione

Allegati


Demo


http://www.mediafire.com/file/deynydlzzyg/Threat System v1.0 Demo.rar


Screen

http://img638.imageshack.us/img638/6422/minaccia.png

Istruzioni per l'uso

All'interno dello script

Bugs e Conflitti Noti

 

N/A

 

 

 

#==============================================================================
# ** Threat System
#------------------------------------------------------------------------------
# by Fantasist
# Version: 1.0
# Date: 13-July-2009
#Traduzione SIMO696
#------------------------------------------------------------------------------
# Version History:
#
# 1.0 - First version
#------------------------------------------------------------------------------
# Descrizione:
# Durante la battaglia, i nemici possono scegliere i propri obiettivi sulla base
# della loro "minaccia" Piuttosto che in modo casuale. La minaccia di un Pg cambia
# a seconda di ciò che fa.Ad esempio, attaccando il livello di minaccia aumenta e
# difendendo il livello minaccia diminuisce.
#
#------------------------------------------------------------------------------
# Compatibilita':
#
# Potrebbe essere incompatibile con i sistemi di combattimento o con altri addons
# per la battaglia.
#------------------------------------------------------------------------------
# Istruzioni:
#
# Posiziona questo script sotto main
#------------------------------------------------------------------------------
# Configurazione:
#
# Scorrere verso il basso e vedrete la configurazione.
#
# ATTACK_THREAT: Il livello di minaccia aumenta quando il pg attacca
# DEFEND_THREAT: Il livello di minaccia diminuisce quando il pg difende
# THREAT_CHANCE: La possibilità che i nemici attaccano un pg piuttosto che un
# altro e' basata sul livello di minaccia
# THREAT_DISPLAY: Il livello di minaccia dei pg appare sopra i loro nomi durante
# le battaglie
# THREAT_WINDOW: Se attivare o disattivare la finestra minaccia. Per attivarlo,
# deve essere impostato su "true". Se si desidera impostare la sua posizione e\o larghezza,
# si può anche impostare un array con la sua posizione X, Y e la larghezza
# (per esempio: [0, 64, 160]).
#
# Skill Threat Configuration:
#
# Guarda e segui l'esempio "SKILL THREAT CONFIG BEGIN"
# In the given example:
#
# when 57 then [10, -2]
#
# la magia 57 (Cross Cut) aumenta la minaccia di chi la ha usata di 10 e diminuisce
# quella del resto del gruppo di 2.
#
# Item Threat Configuration:
#
# Funziona esattamente come la "Skill Threat Configuration
#------------------------------------------------------------------------------
# Crediti:
#
# Fantasist, per averlo fatto
# KCMike20, per la richiesta di questo script
# SIMO696 , per la traduzione di questo script
# Ringraziamenti:
#
# Blizzard, per avermi aiutato
# winkio, per avermi aiutato
# Jackolas, per segnalare un bug
#------------------------------------------------------------------------------
#==============================================================================
# ** ThreatConfig module
#------------------------------------------------------------------------------
# Modulo per le impostazioni e la configurazione del sistema delle minacce.
#==============================================================================

module ThreatConfig
	#--------------------------------------------------------------------------
	# * Config
	#--------------------------------------------------------------------------
	ATTACK_THREAT = 1 # Il livello di minaccia aumenta quando il giocatore attacca
	DEFEND_THREAT = 1 # Il livello di minaccia diminuisce quando il giocatore difende
	THREAT_CHANCE = 100 # La possibilità che i nemici attaccano un pg piuttosto che un
	# altro e' basata sul livello di minaccia
	THREAT_DISPLAY = true # Il livello di minaccia dei pg appare sopra i loro nomi durante
	# le battaglie
	THREAT_WINDOW = [480, 64, 160] # Per abilitare o disattivare la finestra
	#--------------------------------------------------------------------------
	# * Configure skill threats
	#--------------------------------------------------------------------------
	def self.get_skill_threat(skill_id)
		threat = case skill_id
		#========================================================================
		# SKILL THREAT CONFIG BEGIN
		#========================================================================
	when 57 then [5, -1] # Cross Cut
	when 61 then [5, -1] # Leg Sweep
	when 7 then [5, 0] # Fire
		# when skill_ID then [ user_threat, party_threat ]
		#========================================================================
		# SKILL THREAT CONFIG END
		#========================================================================
	else false
	end
	return threat
end
#--------------------------------------------------------------------------
# * Configure item threats
#--------------------------------------------------------------------------
def self.get_item_threat(item_id)
	threat = case item_id
	#========================================================================
	# ITEM THREAT CONFIG BEGIN
	#========================================================================
when 1 then [2, -5] # Potion
	# when item_ID then [ user_threat, party_threat ]
	#========================================================================
	# ITEM THREAT CONFIG END
	#========================================================================
else false
end
return threat
end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# Added the threat attribute.
#==============================================================================

class Game_Actor
#--------------------------------------------------------------------------
# * Initialize threat attribute
#--------------------------------------------------------------------------
alias game_actor_threat_setup setup
def setup(actor_id)
@threat = 0
game_actor_threat_setup(actor_id)
end
#--------------------------------------------------------------------------
# * Get the threat attribute
#--------------------------------------------------------------------------
attr_reader :threat
#--------------------------------------------------------------------------
# * Set the threat attribute
#--------------------------------------------------------------------------
def threat=(val)
val = 0 if val < 0
@threat = val
end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# Modified random actor selection to select by threat.
#==============================================================================

class Game_Party
#--------------------------------------------------------------------------
# * Choose actor by threat
#--------------------------------------------------------------------------
alias choose_actor_threat_orig random_target_actor
def random_target_actor(hp0 = false)
if rand(100) >= ThreatConfig::THREAT_CHANCE
	return choose_actor_threat_orig(hp0)
else
	return threat_target_actor(hp0)
end
end
#--------------------------------------------------------------------------
# * Calculate threat and choose actor
#--------------------------------------------------------------------------
def threat_target_actor(hp0=false)
# Collect valid actors
targets = []
for actor in @actors
	next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
	targets.push(actor)
end
# Get actors with maximum threat
targets.sort! {|a, b| b.threat - a.threat}
targets = targets.find_all {|a| a.threat == targets[0].threat}
# Choose random
target = targets[rand(targets.size)]
return target
end
end

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# Added attack and skill threat handling.
#==============================================================================

class Game_Battler
#--------------------------------------------------------------------------
# * Attack Threat
#--------------------------------------------------------------------------
alias attack_effect_threat attack_effect
def attack_effect(attacker)
attacker.threat += ThreatConfig::ATTACK_THREAT if attacker.is_a?(Game_Actor)
attack_effect_threat(attacker)
end
#--------------------------------------------------------------------------
# * Skill Threat
#--------------------------------------------------------------------------
alias skill_effect_threat skill_effect
def skill_effect(user, skill)
threat = user.is_a?(Game_Actor) && ThreatConfig.get_skill_threat(skill.id)
if threat
	user_threat, party_threat = threat[0], threat[1]
	for actor in $game_party.actors
		threat_plus = actor.id == user.id ? user_threat : party_threat
		actor.threat += threat_plus
	end
end
skill_effect_threat(user, skill)
end
end

#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# Added defend and item threat handling and realtime target selection.
#==============================================================================

class Scene_Battle
#--------------------------------------------------------------------------
# * Defend Threat
#--------------------------------------------------------------------------
alias basic_action_threat_result make_basic_action_result
def make_basic_action_result
if @active_battler.current_action.basic == 1 && @active_battler.is_a?(Game_Actor)
	@active_battler.threat -= ThreatConfig::DEFEND_THREAT
end
basic_action_threat_result
end
#--------------------------------------------------------------------------
# * Item Threat
#--------------------------------------------------------------------------
alias item_action_threat_result make_item_action_result
def make_item_action_result
item_action_threat_result
threat = @active_battler.is_a?(Game_Actor) && ThreatConfig.get_item_threat(@item.id)
if threat
	user_threat, party_threat = threat[0], threat[1]
	for actor in $game_party.actors
		threat_plus = actor.id == @active_battler.id ? user_threat : party_threat
		actor.threat += threat_plus
	end
end
end
#--------------------------------------------------------------------------
# * Choose target actor in realtime
#--------------------------------------------------------------------------
alias update_phase4_step2_choose_actor_realtime update_phase4_step2
def update_phase4_step2
@active_battler.make_action if @active_battler.is_a?(Game_Enemy)
update_phase4_step2_choose_actor_realtime
end
#--------------------------------------------------------------------------
# * Clear threats before battle
#--------------------------------------------------------------------------
alias clear_threats_start_phase1 start_phase1
def start_phase1
clear_threats_start_phase1
$game_party.actors.each {|actor| actor.threat = 0}
end
end

if ThreatConfig::THREAT_DISPLAY
#==============================================================================
# ** Window_BattleStatus
#------------------------------------------------------------------------------
# Modded to show threat beside actor's name.
#==============================================================================

class Window_BattleStatus
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias threat_display_refresh refresh
def refresh
	threat_display_refresh
	for i in 0...$game_party.actors.size
		actor = $game_party.actors[i]
		next if actor.threat == 0
		actor_x = i * 160 + 4
		actor_x += self.contents.text_size(actor.name).width + 4
		self.contents.draw_text(actor_x, 0, 160, 32, "(#{actor.threat})")
	end
end
end
end

if ThreatConfig::THREAT_WINDOW
#==============================================================================
# ** Window_Threat
#------------------------------------------------------------------------------
# This window displays the threats of actors in the party.
#==============================================================================

class Window_Threat < Window_Base
H = 18
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
	a = ThreatConfig::THREAT_WINDOW
	if a.is_a?(Array)
		x, y, w = a[0], a[1], a[2]
	else
		x, y, w = 0, 64, 160
	end
	super(x, y, w, 32 + H + $game_party.actors.size * H)
	@threats = []
	$game_party.actors.each {|a| @threats.push(a.threat)}
	self.contents = Bitmap.new(w-32, self.height-32)
	self.contents.font.size = H
	self.contents.font.bold = H <= 22
	self.opacity = 160
	refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
	self.contents.clear
	self.contents.draw_text(0, 0, self.width-32, H, 'Threats', 1)
	$game_party.actors.each_with_index {|a, i| y_off = H
	self.contents.draw_text(0, y_off + i*H, self.width-32, H, a.name)
	self.contents.draw_text(0, y_off + i*H, self.width-32, H, @threats[i].to_s, 2)}
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
	flag = false
	$game_party.actors.each_with_index {|a, i|
	@threats[i] = a.threat if a.threat != @threats[i]
	flag = true}
	refresh if flag
end
end

#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# Modded to handle threat window.
#==============================================================================

class Scene_Battle
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias threat_win_init main
def main
	@threat_win = Window_Threat.new
	threat_win_init
	@threat_win.dispose
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias threat_win_upd update
def update
	@threat_win.update
	threat_win_upd
end
end
end

 

 

Edited by Dilos
Script monoriga sistemato.
I'm working for a new project
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...