OnBuyItem:
set .@TotalCost,0;
// Calcula o custo total
for(set .@i,0; .@i < getarraysize( @bought_nameid ); set .@i,.@i+1)
for(set .@j,0; .@j < getarraysize( .Items ); set .@j,.@j+1)
if( .Items[.@j] == @bought_nameid[.@i] )
set .@TotalCost,.@TotalCost + ( .Costs[.@j] * @bought_quantity[.@i] );
if( #CASHPOINTS >= .@TotalCost ){
// Deduz #CASHPOINTS e Ganha Itens.
set #CASHPOINTS,#CASHPOINTS - .@TotalCost;
for(set .@i,0; .@i < getarraysize( @bought_nameid ); set .@i,.@i+1)
getitem @bought_nameid[.@i],@bought_quantity[.@i];
// Atribui a quantia de imposto igualmente a outras Guildas.
for( set .@i,0; .@i < getarraysize( .CastleMap$ ); set .@i,.@i + 1 ) {
set .@castleGuild, getguildid(getguildname(getcastledata(.CastleMap$[.@i],1)));
set .@guildCastles, 0; // Counter for guild-owned castles
// Count guild-owned castles
for( set .@j, 0; .@j < getarraysize(.CastleMap$); set .@j, .@j + 1) {
if(getguildid(getguildname(getcastledata(.CastleMap$[.@j],1))) == .@castleGuild) {
set .@guildCastles, .@guildCastles + 1;
}
}
// distriubir imposto igualmente
setd( "$GuildTax_"+.@i ),getd( "$GuildTax_"+.@i ) + ( (( .@TotalCost * .TaxRate ) / 100 ) / .@guildCastles );
}
// Notificação sobre o Total de Imposto Recebido pela Guilda.
message strcharinfo(0),"Imposto recolhido: "+(( .@TotalCost * .TaxRate ) / 100 )+" Cash";
}else{
mes "Você não tem #CASHPOINTS suficiente...";
}
close;