gambuzzi

engine.og

May 11th, 2015
12
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package rpgkata
  2.  
  3. import (
  4.   "fmt"
  5.   "math/rand"
  6.   "time"
  7. )
  8.  
  9. func printDamage(tick int, p1 *Player, p2 *Player, ph1 *Player, ph2 *Player) {
  10.   sh1 := fmt.Sprintf("%d", ph1.Health)
  11.   sh2 := fmt.Sprintf("%d", ph2.Health)
  12.  
  13.   if ph1.ArmorName != "'None'" {
  14.     sh1 = fmt.Sprintf("(%d,%d)", ph1.ArmorHealth, ph1.Health)
  15.   }
  16.   if ph2.ArmorName != "'None'" {
  17.     sh2 = fmt.Sprintf("(%d,%d)", ph2.ArmorHealth, ph2.Health)
  18.   }
  19.  
  20.   fmt.Printf("%d,%s,%s,%s,%d,%s,%s", tick, p1.Name, p2.Name, p1.Weapon, p1.DealedDamage, sh1, sh2)
  21.   if p1.DamageVariable > 0 && p1.DealedDamage == p1.DamageFixed+p1.DamageVariable {
  22.     fmt.Printf(",critical")
  23.   }
  24.   fmt.Printf("\n")
  25. }
  26.  
  27. func Run(players []*Player) int {
  28.   counter := len(players)
  29.   rand.Seed(time.Now().UnixNano())
  30.   //weapon type 3
  31.   for idx := range players {
  32.     otherIdx := counter - 1 - idx
  33.     if players[idx].WeaponType == 3 {
  34.       players[idx].Weapon, players[idx].WeaponType, players[idx].DamageFixed, players[idx].DamageVariable, players[otherIdx].Weapon, players[otherIdx].WeaponType, players[otherIdx].DamageFixed, players[otherIdx].DamageVariable = players[otherIdx].Weapon, players[otherIdx].WeaponType, players[otherIdx].DamageFixed, players[otherIdx].DamageVariable, players[idx].Weapon, players[idx].WeaponType, players[idx].DamageFixed, players[idx].DamageVariable
  35.     }
  36.   }
  37.   //init
  38.   tick := 1
  39.  
  40.   for {
  41.     nothing := true
  42.  
  43.     for _, player := range players {
  44.       if player.Health <= 0 {
  45.         fmt.Printf("%d,%s,Dead\n", tick, player.Name)
  46.       }
  47.     }
  48.  
  49.     if players[0].Health <= 0 || players[1].Health <= 0 {
  50.       break
  51.     }
  52.  
  53.     for idx := range players {
  54.       if tick%players[idx].Speed == 0 {
  55.         otherIdx := counter - 1 - idx
  56.         damage := players[idx].DamageFixed + rand.Intn(players[idx].DamageVariable+1)
  57.  
  58.         //Weapon type 2
  59.         players[idx].AttackCounter++
  60.         if players[idx].WeaponType == 2 {
  61.           if players[idx].AttackCounter%2 == 0 {
  62.             damage *= 2
  63.           }
  64.         }
  65.  
  66.         if damage <= players[otherIdx].ArmorHealth {
  67.           players[otherIdx].ArmorHealth -= damage
  68.         } else {
  69.           players[otherIdx].Health -= damage - players[otherIdx].ArmorHealth
  70.           players[otherIdx].ArmorHealth = 0
  71.         }
  72.  
  73.         players[idx].DealedDamage = damage
  74.  
  75.         //Weapon type 1
  76.         if players[idx].WeaponType == 1 {
  77.           players[idx].Health += damage
  78.           if players[idx].Health > players[idx].MaxHealth {
  79.             players[idx].Health = players[idx].MaxHealth
  80.           }
  81.         }
  82.  
  83.         printDamage(tick, players[idx], players[counter-1-idx], players[0], players[1]) //vincolo a 2 giocatori
  84.         nothing = false
  85.       }
  86.     }
  87.  
  88.     for idx := range players {
  89.       if players[idx].Health < 0 {
  90.         players[idx].Health = 0
  91.       }
  92.     }
  93.  
  94.     if nothing {
  95.       fmt.Printf("%d,NOTHING\n", tick)
  96.     }
  97.  
  98.     tick++
  99.   }
  100.  
  101.   for idx, player := range players {
  102.     if player.Health > 0 {
  103.       fmt.Println(player.Name)
  104.       return idx+1
  105.     }
  106.   }
  107.  
  108.   fmt.Println("TIE")
  109.   return 0
  110.  
  111. }
RAW Paste Data