Skip to content

Instantly share code, notes, and snippets.

@dekart
Forked from chizhovdee/distribution_chips
Created June 29, 2013 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekart/5891709 to your computer and use it in GitHub Desktop.
Save dekart/5891709 to your computer and use it in GitHub Desktop.
CLAN_ID = 1
clan = Clan.find(CLAN_ID)
character_ids = ClanMember.connection.select_values(
ClanMember.send(:sanitize_sql, ["SELECT character_id FROM clan_members WHERE clan_id = :clan", :clan => clan.id])
)
position = 0
Character.transaction do
Character.order("level DESC").find(character_ids, :lock => true).each do |character|
position += 1
if character_ids.size <= 20 && position <= 10
character.chips += 2
elsif character_ids.size > 20 && position <= 20
character.chips += 2
else
character.chips += 1
end
character.save!
end
clan.chips = 0
clan.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment