Closes #4463. Added Shrapnel, as well as variable velocity and arc for bullets

This commit is contained in:
Chicken man
2014-04-04 21:06:40 -04:00
parent 4d08093d1d
commit e6c0a00604
6 changed files with 135 additions and 12 deletions

View File

@@ -76,6 +76,7 @@
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="ThrowsShrapnel.cs" />
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
<Compile Include="Render\WithCrumbleOverlay.cs" />
<Compile Include="PaletteFromR8.cs" />
@@ -120,7 +121,5 @@ cd "$(SolutionDir)"</PostBuildEvent>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Render\" />
</ItemGroup>
<ItemGroup />
</Project>

View File

@@ -0,0 +1,79 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.GameRules;
using OpenRA.FileFormats;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Traits;
namespace OpenRA.Mods.D2k
{
public class ThrowsShrapnelInfo : ITraitInfo
{
[WeaponReference]
public string[] Weapons = { };
public int[] Pieces = { 3, 10 };
public WRange[] Range = { WRange.FromCells(2), WRange.FromCells(5) };
public object Create(ActorInitializer actor) { return new ThrowsShrapnel(this); }
}
class ThrowsShrapnel : INotifyKilled
{
readonly ThrowsShrapnelInfo info;
public ThrowsShrapnel(ThrowsShrapnelInfo info)
{
this.info = info;
}
public void Killed(Actor self, AttackInfo attack)
{
foreach (var name in info.Weapons)
{
var wep = Rules.Weapons[name];
var pieces = self.World.SharedRandom.Next(info.Pieces[0], info.Pieces[1]);
var range = self.World.SharedRandom.Next(info.Range[0].Range, info.Range[1].Range);
for (var i = 0; pieces > i; i++)
{
var rotation = WRot.FromFacing(self.World.SharedRandom.Next(1024));
var args = new ProjectileArgs
{
Weapon = wep,
Facing = self.World.SharedRandom.Next(-1,255),
FirepowerModifier = self.TraitsImplementing<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier())
.Product(),
Source = self.CenterPosition,
SourceActor = self,
PassiveTarget = self.CenterPosition + new WVec(range, 0, 0).Rotate(rotation)
};
self.World.AddFrameEndTask(x =>
{
if (args.Weapon.Projectile != null)
{
var projectile = args.Weapon.Projectile.Create(args);
if (projectile != null)
self.World.Add(projectile);
if (args.Weapon.Report != null && args.Weapon.Report.Any())
Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
}
});
}
}
}
}
}