|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"log"
|
|
|
+ "math/rand"
|
|
|
"time"
|
|
|
|
|
|
"gorm.io/driver/sqlite"
|
|
@@ -108,11 +109,38 @@ type Ship struct {
|
|
|
ArmorPlates uint64
|
|
|
RepairBays uint64
|
|
|
RepairDrones uint64
|
|
|
- ShieldCapacitors uint64
|
|
|
+ ShieldCapacitors uint64
|
|
|
ShieldGenerators uint64
|
|
|
Engines uint64
|
|
|
}
|
|
|
|
|
|
+func (s *Ship) Mass() uint64 {
|
|
|
+ m := uint64(0)
|
|
|
+ m += s.Guns
|
|
|
+ m += s.RocketLaunchers
|
|
|
+ m += (s.ArmorPlates * 2)
|
|
|
+ m += s.RepairBays
|
|
|
+ m += s.ShieldCapacitors
|
|
|
+ m -= s.Engines
|
|
|
+ return m
|
|
|
+}
|
|
|
+
|
|
|
+func (s *Ship) FireGuns() uint64 {
|
|
|
+ total := 0
|
|
|
+ for range make([]byte, s.Guns) {
|
|
|
+ total += rand.Intn(3)
|
|
|
+ }
|
|
|
+ return uint64(total)
|
|
|
+}
|
|
|
+
|
|
|
+func (s *Ship) DroneRepair() uint64 {
|
|
|
+ total := 0
|
|
|
+ for range make([]byte, s.RepairDrones) {
|
|
|
+ total += rand.Intn(2)
|
|
|
+ }
|
|
|
+ return uint64(total)
|
|
|
+}
|
|
|
+
|
|
|
func (db *DataBase) SaveShip(ship *Ship) error {
|
|
|
result := db.DB.Save(ship)
|
|
|
return result.Error
|
|
@@ -123,11 +151,13 @@ type User struct {
|
|
|
Name string `gorm:"unique"`
|
|
|
RealName string `gorm:"UniqueIndex,colate:nocase"`
|
|
|
|
|
|
- Xp uint64
|
|
|
- Metal uint64
|
|
|
- Circuit uint64
|
|
|
- Rockets uint64
|
|
|
- Fuel uint64
|
|
|
+ Xp uint64
|
|
|
+ Metal uint64
|
|
|
+ Circuit uint64
|
|
|
+ MetalBanked uint64
|
|
|
+ CircuitBanked uint64
|
|
|
+ Rockets uint64
|
|
|
+ Fuel uint64
|
|
|
|
|
|
Ship *Ship
|
|
|
|