I'm really wondering if I should offer a way to game developers to develop their logic via some sort of graphical programming and avoid to write scripts like they currently need to do to customize the behaviors. This is what I have for the default monster behavior for example:
Code: Select all
// Default monster behavior. If not re-written on the monster code, this default code will be used.
// Function called on each game loop to run monster attacks, or others.
function Handle(monster)
{
// If the player is in a NPC dialog the monster should just randomly walk around.
if(Player.IsInDialog() == true)
{
Monster.RandomWalk(monster);
return true;
}
// If the monster is near the player, he shall try to attack.
if(Actor.DistanceToPlayer(monster) <= Monster.RetreiveSetting(monster,'ProximityAttack'))
{
Attack(monster);
return true;
}
// Moves toward the player if it's nearer than 10 tiles.
Monster.HuntWalk(monster, 10);
// If we returns false the engine would handle it for us.
return true;
}
// Handle Monster attacks.
function Attack(monster)
{
if(Actor.DistanceToPlayer(monster) > Monster.RetreiveSetting(monster,'ProximityAttack'))
return false;
if(Actor.IsAnimationRunning(monster))
return false;
// Check if at least @BaseRechargeSpeed@ sec passed between the attacks. If not skip the attack.
if(Actor.TimerRunning(monster, 'Attack'))
return false;
// Starts the Attack timer, to avoid to attack too frequently.
Actor.StartTimer(monster, 'Attack', Monster.RetreiveSetting(monster,'AttackSpeed'));
Actor.SetAnimation(monster, 'attack');
Actor.ExecuteWhenAnimationDone(monster, 'AttackAnimationDone');
return true;
}
// Attack after the animation is done
function AttackAnimationDone(monster)
{
damage = Monster.RetreiveSetting(monster, 'BaseDamage');
damage = damage - Inventory.GetWearedEffect('Protection');
if(damage <= 0)
return true;
Player.ReduceStat('Life',damage);
Player.SetAnimation('damage');
return true;
}