Skip to content

Instantly share code, notes, and snippets.

@chizhovdee
Last active December 19, 2015 02:29
Show Gist options
  • Save chizhovdee/5883351 to your computer and use it in GitHub Desktop.
Save chizhovdee/5883351 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