到底有多强
This commit is contained in:
71
Source/WulaFallenEmpire/Pawn/Comp_MultiTurretGun.cs
Normal file
71
Source/WulaFallenEmpire/Pawn/Comp_MultiTurretGun.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_MultiTurretGun : CompProperties_TurretGun
|
||||
{
|
||||
public int ID;
|
||||
public CompProperties_MultiTurretGun()
|
||||
{
|
||||
compClass = typeof(Comp_MultiTurretGun);
|
||||
}
|
||||
}
|
||||
public class Comp_MultiTurretGun : CompTurretGun
|
||||
{
|
||||
private bool fireAtWill = true;
|
||||
public new CompProperties_MultiTurretGun Props => (CompProperties_MultiTurretGun)props;
|
||||
public override void CompTick()
|
||||
{
|
||||
base.CompTick();
|
||||
if (!currentTarget.IsValid && burstCooldownTicksLeft <= 0)
|
||||
{
|
||||
// 在其他情况下没有目标且冷却结束时也回正
|
||||
curRotation = parent.Rotation.AsAngle + Props.angleOffset;
|
||||
}
|
||||
}
|
||||
private void MakeGun()
|
||||
{
|
||||
gun = ThingMaker.MakeThing(Props.turretDef);
|
||||
UpdateGunVerbs();
|
||||
}
|
||||
private void UpdateGunVerbs()
|
||||
{
|
||||
List<Verb> allVerbs = gun.TryGetComp<CompEquippable>().AllVerbs;
|
||||
for (int i = 0; i < allVerbs.Count; i++)
|
||||
{
|
||||
Verb verb = allVerbs[i];
|
||||
verb.caster = parent;
|
||||
verb.castCompleteCallback = delegate
|
||||
{
|
||||
burstCooldownTicksLeft = AttackVerb.verbProps.defaultCooldownTime.SecondsToTicks();
|
||||
};
|
||||
}
|
||||
}
|
||||
public override void PostExposeData()
|
||||
{
|
||||
Scribe_Values.Look(ref burstCooldownTicksLeft, "burstCooldownTicksLeft", 0);
|
||||
Scribe_Values.Look(ref burstWarmupTicksLeft, "burstWarmupTicksLeft", 0);
|
||||
Scribe_TargetInfo.Look(ref currentTarget, "currentTarget_" + Props.ID);
|
||||
Scribe_Deep.Look(ref gun, "gun_" + Props.ID);
|
||||
Scribe_Values.Look(ref fireAtWill, "fireAtWill", defaultValue: true);
|
||||
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
||||
{
|
||||
if (gun == null)
|
||||
{
|
||||
Log.Error("CompTurrentGun had null gun after loading. Recreating.");
|
||||
MakeGun();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateGunVerbs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
128
Source/WulaFallenEmpire/Pawn/Comp_PawnRenderExtra.cs
Normal file
128
Source/WulaFallenEmpire/Pawn/Comp_PawnRenderExtra.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_PawnRenderExtra : CompProperties
|
||||
{
|
||||
public CompProperties_PawnRenderExtra()
|
||||
{
|
||||
this.compClass = typeof(Comp_PawnRenderExtra);
|
||||
}
|
||||
|
||||
public string path;
|
||||
|
||||
public Vector3 size;
|
||||
|
||||
public Color colorAlly;
|
||||
|
||||
public Color colorEnemy;
|
||||
|
||||
public ShaderTypeDef shader;
|
||||
|
||||
public DrawData drawData;
|
||||
}
|
||||
[StaticConstructorOnStartup]
|
||||
public class Comp_PawnRenderExtra : ThingComp
|
||||
{
|
||||
public CompProperties_PawnRenderExtra Props
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.props as CompProperties_PawnRenderExtra;
|
||||
}
|
||||
}
|
||||
|
||||
private Pawn ParentPawn
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.parent as Pawn;
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostDraw()
|
||||
{
|
||||
base.PostDraw();
|
||||
if (!this.ParentPawn.Dead && !this.ParentPawn.Downed && this.ParentPawn.CurJobDef != JobDefOf.MechCharge && this.ParentPawn.CurJobDef != JobDefOf.SelfShutdown)
|
||||
{
|
||||
this.DrawPawnRenderExtra();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawPawnRenderExtra()
|
||||
{
|
||||
Vector3 pos = this.ParentPawn.DrawPos;
|
||||
if (this.ParentPawn.Faction == Faction.OfPlayer || !this.ParentPawn.Faction.HostileTo(Faction.OfPlayer))
|
||||
{
|
||||
this.color = this.Props.colorAlly;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.color = this.Props.colorEnemy;
|
||||
}
|
||||
string graphic = this.GetPawnRenderExtra();
|
||||
Vector3 offset = GetOffsetByRot();
|
||||
float layer = GetLayerByRot();
|
||||
pos.y = AltitudeLayer.Pawn.AltitudeFor(layer);
|
||||
|
||||
Matrix4x4 matrix = default(Matrix4x4);
|
||||
matrix.SetTRS(pos + offset, Quaternion.AngleAxis(0f, Vector3.up), this.Props.size);
|
||||
Material material = MaterialPool.MatFrom(graphic, this.Props.shader.Shader, this.color);
|
||||
Graphics.DrawMesh(MeshPool.plane10, matrix, material, (int)layer);
|
||||
}
|
||||
|
||||
public Vector3 GetOffsetByRot()
|
||||
{
|
||||
Vector3 result;
|
||||
if (this.Props.drawData != null)
|
||||
{
|
||||
result = this.Props.drawData.OffsetForRot(this.ParentPawn.Rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Vector3.zero;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public float GetLayerByRot()
|
||||
{
|
||||
float result;
|
||||
if (this.Props.drawData != null)
|
||||
{
|
||||
result = this.Props.drawData.LayerForRot(this.ParentPawn.Rotation, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetPawnRenderExtra()
|
||||
{
|
||||
if (this.ParentPawn.Rotation.AsInt == 0)
|
||||
{
|
||||
return this.Props.path + "_north";
|
||||
}
|
||||
if (this.ParentPawn.Rotation.AsInt == 1)
|
||||
{
|
||||
return this.Props.path + "_east";
|
||||
}
|
||||
if (this.ParentPawn.Rotation.AsInt == 2)
|
||||
{
|
||||
return this.Props.path + "_south";
|
||||
}
|
||||
if (this.ParentPawn.Rotation.AsInt == 3)
|
||||
{
|
||||
return this.Props.path + "_west";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Color color;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user