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="WithMuzzleFlash.cs" />
<Compile Include="WithShadow.cs" /> <Compile Include="WithShadow.cs" />
<Compile Include="NukePaletteEffect.cs" /> <Compile Include="NukePaletteEffect.cs" />
<Compile Include="GainsExperience.cs" />
<Compile Include="GivesExperience.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

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

View File

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

View File

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