fix tk detection; fix crash on lacking ValuedInfo; fix traits being fetched twice; fix needless mutation of 'exp'
This commit is contained in:
@@ -16,86 +16,75 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.GameRules;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
using System.Linq;
|
||||||
using System.Linq;
|
using OpenRA.GameRules;
|
||||||
using System.Collections.Generic;
|
using OpenRA.Mods.RA.Effects;
|
||||||
using OpenRA.Mods.RA.Effects;
|
using OpenRA.Traits;
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
namespace OpenRA.Mods.RA
|
||||||
public class GainsExperienceInfo : ITraitInfo
|
{
|
||||||
{
|
public class GainsExperienceInfo : ITraitInfo
|
||||||
//public readonly float[] CostThreshold = {2,4,8};
|
{
|
||||||
public readonly float[] CostThreshold = {1, 1.5f, 2};
|
//public readonly float[] CostThreshold = {2,4,8};
|
||||||
public readonly float[] FirepowerModifier = {1.2f, 1.5f, 2};
|
public readonly float[] CostThreshold = { 1, 1.5f, 2 };
|
||||||
public readonly float[] ArmorModifier = {1.2f, 1.5f, 2};
|
public readonly float[] FirepowerModifier = { 1.2f, 1.5f, 2 };
|
||||||
public readonly float[] SpeedModifier = {1.2f, 1.5f, 2};
|
public readonly float[] ArmorModifier = { 1.2f, 1.5f, 2 };
|
||||||
public object Create(Actor self) { return new GainsExperience(self, this); }
|
public readonly float[] SpeedModifier = { 1.2f, 1.5f, 2 };
|
||||||
}
|
public object Create(Actor self) { return new GainsExperience(self, this); }
|
||||||
|
}
|
||||||
public class GainsExperience: IFirepowerModifier, ISpeedModifier, IDamageModifier
|
|
||||||
{
|
public class GainsExperience : IFirepowerModifier, ISpeedModifier, IDamageModifier
|
||||||
readonly Actor self;
|
{
|
||||||
readonly List<float> Levels;
|
readonly Actor self;
|
||||||
readonly GainsExperienceInfo Info;
|
readonly List<float> Levels;
|
||||||
public GainsExperience(Actor self, GainsExperienceInfo info)
|
readonly GainsExperienceInfo Info;
|
||||||
{
|
public GainsExperience(Actor self, GainsExperienceInfo info)
|
||||||
this.self = self;
|
{
|
||||||
this.Info = info;
|
this.self = self;
|
||||||
System.Console.WriteLine(self.Info.Name);
|
this.Info = info;
|
||||||
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||||
Levels = Info.CostThreshold.Select(t => t*cost).ToList();
|
Levels = Info.CostThreshold.Select(t => t * cost).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
int Experience = 0;
|
int Experience = 0;
|
||||||
[Sync]
|
[Sync]
|
||||||
int Level = 0;
|
int Level = 0;
|
||||||
|
|
||||||
public void GiveExperience(int amount)
|
public void GiveExperience(int amount)
|
||||||
{
|
{
|
||||||
// Already at max level
|
Experience += amount;
|
||||||
if (Level == Levels.Count() - 1)
|
|
||||||
return;
|
while (Level < Levels.Count() - 1 && Experience > Levels[Level])
|
||||||
|
{
|
||||||
Experience += amount;
|
Level++;
|
||||||
|
|
||||||
if (Experience > Levels[Level])
|
// TODO: Show an effect or play a sound or something
|
||||||
{
|
Log.Write("{0} became Level {1}".F(self.Info.Name, Level));
|
||||||
Level++;
|
|
||||||
|
self.World.AddFrameEndTask(w =>
|
||||||
// TODO: Show an effect or play a sound or something
|
{
|
||||||
System.Console.WriteLine("{0} became Level {1}",self.Info.Name, Level);
|
w.Add(new CrateEffect(self, "speed"));
|
||||||
|
});
|
||||||
self.World.AddFrameEndTask(w =>
|
}
|
||||||
{
|
}
|
||||||
w.Add(new CrateEffect(self, "speed"));
|
|
||||||
});
|
public float GetDamageModifier(WarheadInfo warhead)
|
||||||
}
|
{
|
||||||
}
|
return Level > 0 ? 1 / Info.ArmorModifier[Level - 1] : 1;
|
||||||
|
}
|
||||||
public float GetDamageModifier( WarheadInfo warhead )
|
|
||||||
{
|
public float GetFirepowerModifier()
|
||||||
if (Level == 0)
|
{
|
||||||
return 1.0f;
|
return Level > 0 ? Info.FirepowerModifier[Level - 1] : 1;
|
||||||
|
}
|
||||||
return 1/Info.ArmorModifier[Level - 1];
|
|
||||||
}
|
public float GetSpeedModifier()
|
||||||
public float GetFirepowerModifier()
|
{
|
||||||
{
|
return Level > 0 ? Info.SpeedModifier[Level - 1] : 1;
|
||||||
if (Level == 0)
|
}
|
||||||
return 1.0f;
|
}
|
||||||
|
|
||||||
return Info.FirepowerModifier[Level - 1] ;
|
|
||||||
}
|
|
||||||
public float GetSpeedModifier()
|
|
||||||
{
|
|
||||||
if (Level == 0)
|
|
||||||
return 1.0f;
|
|
||||||
|
|
||||||
return Info.SpeedModifier[Level - 1] ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class GivesExperienceInfo : TraitInfo<GivesExperience> { public readonly int Experience = -1; }
|
class GivesExperienceInfo : TraitInfo<GivesExperience> { public readonly int Experience = -1; }
|
||||||
@@ -32,16 +31,17 @@ namespace OpenRA.Mods.RA
|
|||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
{
|
{
|
||||||
// Prevent TK from giving exp
|
// Prevent TK from giving exp
|
||||||
//if (self.Owner == e.Attacker.Owner)
|
//if (e.Attacker == null || e.Attacker.Owner.Stances[ self.Owner ] == Stance.Ally )
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
var exp = 0;
|
var info = self.Info.Traits.Get<GivesExperienceInfo>();
|
||||||
if (self.Info.Traits.Get<ValuedInfo>() != null)
|
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||||
exp = self.Info.Traits.Get<ValuedInfo>().Cost;
|
|
||||||
if (self.Info.Traits.Get<GivesExperienceInfo>().Experience >= 0)
|
var exp = info.Experience >= 0
|
||||||
exp = self.Info.Traits.Get<GivesExperienceInfo>().Experience;
|
? info.Experience
|
||||||
|
: valued != null ? valued.Cost : 0;
|
||||||
var killer = e.Attacker.traits.WithInterface<GainsExperience>().FirstOrDefault();
|
|
||||||
|
var killer = e.Attacker.traits.GetOrDefault<GainsExperience>();
|
||||||
if (killer != null)
|
if (killer != null)
|
||||||
killer.GiveExperience(exp);
|
killer.GiveExperience(exp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user