StendhalRefactoring: Difference between revisions

Content deleted Content added
imported>MiguelAngelBlanchLardin
imported>MiguelAngelBlanchLardin
Line 105:
 
== Events ==
I see two different approachs here:
# Active one, in the form of ''onAttack'', that requieres something like
=== boolean Player.onAttack(target, weapon)===
{
if(target is of type ghost)
{
return false;
}
return true;
}
# Passive one, in the form of ''onAttacked''
Ghost.onAttacked(source, weapon)
{
return false;
}
 
I think passive approach can lead to simpler more mantenible code. So I break the below list in those two categories.
 
 
Creatures can recieve the next list of events:
 
=== boolean onAttack(target, weapon)===
===Passive way===
''called when attacking a target with the given weapon.''
====boolean onAttacked(attacker, weapon)====
''called when attacked by someone with a given weapon.''
====void onStopAttackonStopAttacked(target)====
''called when we stop attacking target''
===void onStopAttacked(target)===
''called when target stops attacking us''
====boolean onDamage(type, amount)====
''called when entity is damaged with the damage type (physical, fire, poison, magical, ... ) and the amount of damage done.''
====boolean onKilled(attacker, weapon)====
''called when attacked killed us with the given weapon''
====boolean onKillonMove(targetx,y)====
''called when entity ismoves usedto byx,y source( onbefore basemoving itemin fact )''
====boolean onUsedWithonCollidedWith(source, base)====
''called when entity iscollide usedwith byanother sourceentity''
====boolean onDroponEquipped(itemsource, slot)====
''called when entity is equipped on the source entity and in the given slot''
===void=boolean onChatonDropped(source, textx, y)====
''called when entity is dropped by source to floor at position x,y''
====void onChat(source, text)====
''called when someone speaks near entity or write to entity''
====boolean onStoponUsed(source)====
''called when entity is used by source''
====boolean onUsedWith(source, base)====
''called when entity is used by source on base item''
====boolean onStop()====
''called when entity stops moving, attacking, etc...''
 
 
===Active way===
==== boolean onAttack(target, weapon)====
''called when attacking a target with the given weapon.''
====void onStopAttackedonStopAttack(target)====
''called when we stop attacking target''
====boolean onDamage(type, amount)====
''called when entity is damaged with the damage type (physical, fire, poison, magical, ... ) and the amount of damage done.''
====boolean onKill(target)====
''called when entity kills target''
====boolean onMove(x,y)====
''called when entity moves to x,y ( before moving in fact )''
====boolean onCollide(x,y)====
''called when entity collide at position x,y''
====boolean onCollideWith(target)====
''called when entity collide with another entity''
====boolean onEquip(item, slot)====
''called when entity equips item on the given slot''
====boolean onEquippedonDrop(sourceitem, slot)====
''called when entity is equipped on the source entity and in the given slot''
===boolean onDrop(item, slot)===
''called when entity drops item from the given slot to floor''
===boolean=void onDroppedonChat(source, x, ytext)====
''called when entity is dropped by source to floor at position x,y''
===void onChat(source, text)===
''called when someone speaks near entity or write to entity''
====boolean onUse(item)====
''called when entity use item''
====boolean onUseWith(base, item)====
''called when entity use item on base item''
====boolean onUsedonStop(source)====
''called when entity is used by source''
===boolean onUsedWith(source, base)===
''called when entity is used by source on base item''
===boolean onStop()===
''called when entity stops moving, attacking, etc...''