Battle (FA game) ends (=result parsing)

Submitted by Brutus5000 on Fri, 07/22/2016 - 20:05
Goal

After a battle, the result needs to get parsed.

  • update batlle, set status="ended" and winning_faction
  • update battle participant result
    • on death -> set killed_by for character
  • reward XP
    • add XP for ACU kills
    • add XP for experimental kills
    • add XP for victory
  • reward Credits
    • add credits for ACU kills
    • add credits for victory
Input data

Game results have to be parsed outside database.

  • <battle id>
  • <winning faction>
  • list of player result: <character>, <batte result>, <killed experimentals>
  • list of acu_kills: <killed-character>, <killed by-character>
Preconditions

Pretty obvious checking, may prevent cheating or can be skipped?

Battle exists and was running:
SELECT COUNT(id) FROM battles WHERE id = <battle id> AND status = 'R'

Database transaction

UPDATE battles SET status = 'F', ended_at = NOW(), winning_faction = <winning faction> WHERE id = <battle id>

for each row in list of player result:
UPDATE battle_participants SET result = <battle result> WHERE fk_character = <character>

IF <result> = 'V' THEN
---> INSERT into xp_journal (fk_battle, fk_character, reason, amount, created_at) VALUES (<battle id>, <character>, 'V', [XP_FOR_VICTORY], NOW())
---> INSERT INTO credit_journal (fk_character, fk_battle, reason, amount, transaction_date)  VALUES (<character>, <battle id>, 'V', [CREDITS_FOR_VICTORY], NOW() )

IF <killed experimentals> > 0 THEN
---> INSERT into xp_journal (fk_battle, fk_character, reason, amount, created_at) VALUES (<battle id>, <character>, 'X', <killed experimentals> * [XP_FOR_EXPERIMENTALS], NOW())

for each row in list of acu_kills:
---> UPDATE character SET killed_by = <killed by-character> WHERE <killed-character>
---> INSERT into xp_journal (fk_battle, fk_character, reason, amount, created_at) VALUES (<battle id>, <character>, 'K', <killed experimentals> * [XP_FOR_KILL], NOW())
---> INSERT INTO credit_journal (fk_character, fk_battle, reason, amount, transaction_date)  VALUES (<character>, <battle id>, 'K', [CREDITS_FOR_KILL], NOW() )

CALCULATE PROMOTIONS

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.