-
Notifications
You must be signed in to change notification settings - Fork 0
/
TournamentEntry.cs
120 lines (115 loc) · 4.37 KB
/
TournamentEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using Assets.Scripts;
using Assets.Scripts.Persistence;
using BrilliantSkies.Core.Id;
using BrilliantSkies.Ftd.Planets.Instances;
using BrilliantSkies.Ftd.Planets;
using UnityEngine;
using BrilliantSkies.Core.UniverseRepresentation;
namespace w0otness
{
public class TournamentEntry
{
public bool IsKing { get; set; }
public Tournament.SPAWN.DIR spawn_direction { get; set; }
public Tournament.SPAWN.LOC spawn_location { get; set; }
public ObjectId Team_id { get; set; }
public float Res { get; set; }
private BlueprintFile _bpf;
public BlueprintFile Bpf {
get {
return _bpf;
}
set {
_bpf = value;
bp = Bpf.Load();
}
}
public Blueprint bp;
public string[] LabelCost {
get {
if (bp != null) {
var scs = bp.SCs.FindAll(x => !x.IsSubConstructable());
var num = scs.Count;
if (num > 0) {
var s = new string[num + 1];
float smax = 0;
for (int i = 0; i < num; i++) {
float max = scs[i].CalculateResourceCost(false, true).Material;
s[i + 1] = String.Format("{0} <color=cyan>{1}</color>", scs[i].blueprintName, max);
smax += max;
}
s[0] = string.Format("{0} <color=cyan>{1}</color>", bp.blueprintName, bp.CalculateResourceCost(false, true).Material - smax);
return s;
} else {
var s = new string[1];
s[0] = string.Format("{0} <color=cyan>{1}</color>", bp.blueprintName, bp.CalculateResourceCost(false, true).Material);
return s;
}
}
return null;
}
}
public string[] Label {
get {
if (bp != null) {
var scs = bp.SCs.FindAll(x => !x.IsSubConstructable());
var num = scs.Count;
if (num > 0) {
var s = new string[num + 1];
float smax = 0;
float scur = 0;
for (int i = 0; i < num; i++) {
float max = scs[i].CalculateResourceCost(false, true).Material;
float cur = scs[i].CalculateResourceCost(true, true).Material;
s[i + 1] = string.Format("{0} {1}", scs[i].blueprintName, Math.Round(cur / max * 100, 1));
smax += max;
scur += cur;
}
s[0] = string.Format("{0} {1}", bp.blueprintName, Math.Round((bp.CalculateResourceCost(true, true).Material - scur) / (bp.CalculateResourceCost(false, true).Material - smax) * 100, 1));
return s;
} else {
var s = new string[1];
s[0] = string.Format("{0} {1}", bp.blueprintName, Math.Round(bp.CalculateResourceCost(true, true).Material / bp.CalculateResourceCost(false, true).Material * 100, 1));
return s;
}
}
return null;
}
}
public void Spawn(float dis, float gap, int count, int pos)
{
MainConstruct mainConstruct = BlueprintConverter.Convert(bp, ConversionDamageMode.IgnoreDamage, false);
Team_id = IsKing ? InstanceSpecification.i.Factions.Factions.Find(f => f.FactionSpec.AbreviatedName == "K").Id : InstanceSpecification.i.Factions.Factions.Find(f => f.FactionSpec.AbreviatedName == "C").Id;
BlueprintConverter.Initiate(mainConstruct, PlanetList.MainFrame.FramePositionToUniversalPosition(VLoc(gap, count, pos, dis)), VDir(), Team_id, null, SpawnPositioning.OriginOrCentre);
}
public Vector3 VLoc(float gap, int count, int pos, float dis)
{
switch (spawn_location) {
case Tournament.SPAWN.LOC.Sea:
return new Vector3((count - 1) * gap / 2 - (pos * gap), 0, IsKing ? dis / 2 : dis / 2 - dis);
case Tournament.SPAWN.LOC.Air:
return new Vector3((count - 1) * gap / 2 - (pos * gap), 50, IsKing ? dis / 2 : dis / 2 - dis);
case Tournament.SPAWN.LOC.Sub:
return new Vector3((count - 1) * gap / 2 - (pos * gap), -10, IsKing ? dis / 2 : dis / 2 - dis);
case Tournament.SPAWN.LOC.Land:
return new Vector3((count - 1) * gap / 2 - (pos * gap), 51, IsKing ? dis / 2 : dis / 2 - dis);
}
return new Vector3((count - 1) * gap / 2 - (pos * gap), 0, IsKing ? 500 : -500);
}
public Quaternion VDir()
{
switch (spawn_direction) {
case Tournament.SPAWN.DIR.Facing:
return Quaternion.LookRotation(new Vector3(0, 0, IsKing ? -1 : 1));
case Tournament.SPAWN.DIR.Away:
return Quaternion.LookRotation(new Vector3(0, 0, IsKing ? 1 : -1));
case Tournament.SPAWN.DIR.Left:
return Quaternion.LookRotation(new Vector3(IsKing ? 1 : -1, 0, 0));
case Tournament.SPAWN.DIR.Right:
return Quaternion.LookRotation(new Vector3(IsKing ? -1 : 1, 0, 0));
}
return Quaternion.LookRotation(new Vector3(0, 0, IsKing ? -1 : 1));
}
}
}