Units gain exp for kills and level up

This commit is contained in:
Paul Chote
2010-05-27 16:53:21 +12:00
parent c792ce5686
commit c15d721884
6 changed files with 138 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
using System.Linq;
using System.Collections.Generic;
namespace OpenRA.Mods.RA
{
public class GainsExperienceInfo : ITraitInfo
{
//public readonly float[] LevelThresholds = {2,4,8};
public readonly float[] LevelThresholds = {1, 1.5f, 2};
public object Create(Actor self) { return new GainsExperience(self); }
}
public class GainsExperience
{
readonly Actor self;
readonly List<float> Levels;
public GainsExperience(Actor self)
{
this.self = self;
System.Console.WriteLine(self.Info.Name);
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
Levels = self.Info.Traits.Get<GainsExperienceInfo>().LevelThresholds.Select(t => t*cost).ToList();
}
[Sync]
int Experience = 0;
[Sync]
int Level = 0;
public void GiveExperience(int amount)
{
// Already at max level
if (Level == Levels.Count() - 1)
return;
Experience += amount;
if (Experience > Levels[Level])
{
Level++;
// TODO: Show an effect or play a sound or something
System.Console.WriteLine("{0} became Level {1}",self.Info.Name, Level);
}
}
}
}

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
using System.Linq;
namespace OpenRA.Mods.RA
{
class GivesExperienceInfo : TraitInfo<GivesExperience> { public readonly int Experience = -1; }
class GivesExperience : INotifyDamage
{
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
{
// Prevent TK from giving exp
//if (self.Owner == e.Attacker.Owner)
// return;
var exp = 0;
if (self.Info.Traits.Get<ValuedInfo>() != null)
exp = self.Info.Traits.Get<ValuedInfo>().Cost;
if (self.Info.Traits.Get<GivesExperienceInfo>().Experience >= 0)
exp = self.Info.Traits.Get<GivesExperienceInfo>().Experience;
var killer = e.Attacker.traits.WithInterface<GainsExperience>().FirstOrDefault();
if (killer != null)
killer.GiveExperience(exp);
}
}
}
}

View File

@@ -178,6 +178,8 @@
<Compile Include="WithMuzzleFlash.cs" />
<Compile Include="WithShadow.cs" />
<Compile Include="NukePaletteEffect.cs" />
<Compile Include="GainsExperience.cs" />
<Compile Include="GivesExperience.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -12,6 +12,8 @@
IronCurtainable:
HiddenUnderFog:
RevealsShroud:
GainsExperience:
GivesExperience:
^Infantry:
Category: Infantry
@@ -27,6 +29,8 @@
HiddenUnderFog:
RevealsShroud:
TeslaInstantKills:
GainsExperience:
GivesExperience:
^Ship:
Category: Ship
@@ -36,6 +40,8 @@
Selectable:
HiddenUnderFog:
RevealsShroud:
GainsExperience:
GivesExperience:
^Plane:
Category: Plane
@@ -44,6 +50,8 @@
Selectable:
HiddenUnderFog:
RevealsShroud:
GainsExperience:
GivesExperience:
^Building:
Category: Building
@@ -56,6 +64,7 @@
EmitInfantryOnSell:
ActorTypes: e1,e1,e1,c1,c2,e6
MustBeDestroyed:
GivesExperience:
^Wall:
Category: Building
@@ -78,6 +87,7 @@
HasMakeAnimation: false
Palette: terrain
DamageStates: 2
GivesExperience:
^Tree:
Category: Building

View File

@@ -771,6 +771,9 @@ WEAF:
SYRF:
Inherits: ^Building
Valued:
Cost: 50
Description: Fake Shipyard
# Buildable:
# BuildPaletteOrder: 900
# Prerequisites: @Power Plant
@@ -813,6 +816,9 @@ SPEF:
DOMF:
Inherits: ^Building
Valued:
Cost: 50
Description: Fake Radar Dome
# Buildable:
# BuildPaletteOrder: 900
# Prerequisites: proc

View File

@@ -15,6 +15,7 @@ BADR:
Cargo:
Passengers: 10
-Selectable:
-GainsExperience:
BADR.bomber:
CarpetBomb:
@@ -35,6 +36,7 @@ BADR.bomber:
WithShadow:
IronCurtainable:
-Selectable:
-GainsExperience:
V2RL:
Inherits: ^Vehicle