Skip to content

Instantly share code, notes, and snippets.

@qoh
Created March 8, 2013 11:05
Show Gist options
  • Save qoh/5115744 to your computer and use it in GitHub Desktop.
Save qoh/5115744 to your computer and use it in GitHub Desktop.
function Director( %diff_level )
{
if ( !strLen( %diff_level ) || %diff_level < 1 || %diff_level > 3 )
{
%diff_level = 2;
}
%diff_level = mFloor( %diff_level );
%obj = new scriptObject()
{
class = "directorSO";
count = 0;
time = 0;
bonus_rate = 1;
diff_level = %diff_level;
};
%obj._new_choice();
%obj.pointTick = %obj.schedule( 1000, "pointTick" );
%obj.spawnTick = %obj.schedule( 10000 / %obj.bonus_rate, "spawnTick" );
return %obj;
}
function directorSO::_new_choice( %this )
{
%this.choice_index = getRandom( 0, $Director::CardCount );
}
function directorSO::_spawn_choice( %this )
{
%cost_raw = $Director::CardCost[ %this.choice_index ];
echo( "spawn" SPC $Director::CardName[ %this.choice_index ] );
if ( getRandom() < 0.5 && %cost_raw * 4 <= %this.points )
{
%this.points -= %cost_raw * 4;
}
}
function directorSO::pointTick( %this )
{
cancel( %this.pointTick );
%this.time++;
%fac1 = min( %this.diff_level - 0.2, 1 );
%fac2 = %this.time / 60;
%fac3 = mFloor( %fac1 * %fac2 );
%fac4 = max( 1, ( 2 * ( %this.diff_level $= 3 ) ) );
%this.points += 2 + %fac3 * %fac4;
%this.pointTick = %this.schedule( 1000, "pointTick" );
}
function directorSO::spawnTick( %this )
{
cancel( %this.spawnTick );
%cost_raw = $Director::CardCost[ %this.choice_index ];
%cost_mod = %cost_raw * ( 1 + ( %this.count * 0.2 ) );
if ( %cost_raw < %self.points / 50 )
{
%this._new_choice();
%this.count = 0;
%this.spawnTick = %this.schedule( 250, "spawnTick" );
return;
}
%delay = ( getRandom() * 6 + 3 ) / %this.bonus_rate;
if ( %this.count >= 4 or %cost_mod >= %this.points )
{
%this._new_choice();
%this.count = 0;
%this.spawnTick = %this.schedule( %delay, "spawnTick" );
return;
}
%this.points -= %cost_mod;
%this.count += 1;
%this.spawn_choice();
%this.spawnTick = %this.schedule( %delay, "spawnTick" );
}
function directorSO::death_event( %this )
{
if ( %this.count )
{
%this.count--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment