Skip to content

Commit

Permalink
Merge branch 'dev' into test-grid
Browse files Browse the repository at this point in the history
  • Loading branch information
asdawej authored Dec 24, 2023
2 parents bbc2903 + 93e4f28 commit 6bd8df6
Show file tree
Hide file tree
Showing 15 changed files with 837 additions and 570 deletions.
13 changes: 3 additions & 10 deletions dependency/proto/Message2Server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,9 @@ message TargetMsg
}
message InstallMsg
{
oneof module_type
{
ConstructorType constructor_type = 1;
ArmorType armor_type = 2;
ShieldType shield_type = 3;
WeaponType weapon_type = 4;
ProducerType producer_type = 5;
}
int64 player_id = 6;
int64 team_id = 7;
ModuleType module_type = 1;
int64 player_id = 2;
int64 team_id = 3;
}
message BuildShipMsg
{
Expand Down
22 changes: 22 additions & 0 deletions dependency/proto/MessageType.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ enum ProducerType
PRODUCER3 = 3;
}

enum ModuleType
{
NULL_MODULE_TYPE = 0;
MODULE_PRODUCER1 = 1;
MODULE_PRODUCER2 = 2;
MODULE_PRODUCER3 = 3;
MODULE_CONSTRUCTOR1 = 4;
MODULE_CONSTRUCTOR2 = 5;
MODULE_CONSTRUCTOR3 = 6;
MODULE_ARMOR1 = 7;
MODULE_ARMOR2 = 8;
MODULE_ARMOR3 = 9;
MODULE_SHIELD1 = 10;
MODULE_SHIELD2 = 11;
MODULE_SHIELD3 = 12;
MODULE_LASERGUN = 13;
MODULE_PLASMAGUN = 14;
MODULE_SHELLGUN = 15;
MODULE_MISSILEGUN = 16;
MODULE_ARCGUN = 17;
}

enum BulletType
{
NULL_BULLET_TYPE = 0;
Expand Down
14 changes: 7 additions & 7 deletions logic/GameClass/GameObj/Map/MapReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MapGenerator;

/// <summary>
/// 地图结构体
/// 地图结构体
/// </summary>
public struct MapStruct(uint height, uint width, uint[,] map)
{
Expand All @@ -15,18 +15,18 @@ public struct MapStruct(uint height, uint width, uint[,] map)
public static class MapReader
{
/// <summary>
/// 读取二进制地图文件
/// 读取二进制地图文件
/// </summary>
/// <param name="mapFile">地图文件路径</param>
/// <param name="dtype">地图文件读取类型</param>
/// <param name="mapFile">地图文件路径</param>
/// <param name="dtype">地图文件读取类型</param>
/// <returns></returns>
public static MapStruct MapRead(string mapFile, char dtype = 'B')
{
var fp = File.OpenRead(mapFile);
BinaryReader br = new(fp);
switch (dtype)
{
#region 以下支持
#region 以下支持

case 'b':
{
Expand Down Expand Up @@ -122,7 +122,7 @@ public static MapStruct MapRead(string mapFile, char dtype = 'B')

#endregion

#region 以下支持但无效
#region 以下支持但无效

case 'l':
{
Expand Down Expand Up @@ -179,7 +179,7 @@ public static MapStruct MapRead(string mapFile, char dtype = 'B')

#endregion

#region 以下不支持
#region 以下不支持

case 'q':
{
Expand Down
21 changes: 21 additions & 0 deletions logic/GameClass/GameObj/Occupations/CivilShip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@ public class CivilShip : IOccupation
public int Cost { get; } = GameData.CivilShipCost;
public int BaseArmor { get; } = GameData.CivilShipBaseArmor;
public int BaseShield { get; } = GameData.CivilShipBaseShield;
public bool IsModuleValid(ModuleType moduleType) => moduleType switch
{
ModuleType.Producer1 => true,
ModuleType.Producer2 => true,
ModuleType.Producer3 => true,
ModuleType.Constructor1 => true,
ModuleType.Constructor2 => true,
ModuleType.Constructor3 => true,
ModuleType.Armor1 => true,
ModuleType.Armor2 => false,
ModuleType.Armor3 => false,
ModuleType.Shield1 => true,
ModuleType.Shield2 => false,
ModuleType.Shield3 => false,
ModuleType.LaserGun => true,
ModuleType.PlasmaGun => false,
ModuleType.ShellGun => false,
ModuleType.MissileGun => false,
ModuleType.ArcGun => false,
_ => false
};
}
21 changes: 21 additions & 0 deletions logic/GameClass/GameObj/Occupations/FlagShip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@ public class FlagShip : IOccupation
public int Cost { get; } = GameData.FlagShipCost;
public int BaseArmor { get; } = GameData.FlagShipBaseArmor;
public int BaseShield { get; } = GameData.FlagShipBaseShield;
public bool IsModuleValid(ModuleType moduleType) => moduleType switch
{
ModuleType.Producer1 => true,
ModuleType.Producer2 => false,
ModuleType.Producer3 => false,
ModuleType.Constructor1 => true,
ModuleType.Constructor2 => false,
ModuleType.Constructor3 => false,
ModuleType.Armor1 => true,
ModuleType.Armor2 => true,
ModuleType.Armor3 => true,
ModuleType.Shield1 => true,
ModuleType.Shield2 => true,
ModuleType.Shield3 => true,
ModuleType.LaserGun => true,
ModuleType.PlasmaGun => true,
ModuleType.ShellGun => true,
ModuleType.MissileGun => true,
ModuleType.ArcGun => true,
_ => false
};
}
2 changes: 2 additions & 0 deletions logic/GameClass/GameObj/Occupations/NullOccupation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Preparation.Interface;
using Preparation.Utility;

namespace GameClass.GameObj.Occupations;

Expand All @@ -11,5 +12,6 @@ public class NullOccupation : IOccupation
public int Cost => 0;
public int BaseArmor => 0;
public int BaseShield => 0;
public bool IsModuleValid(ModuleType moduleType) => false;
private NullOccupation() { }
}
21 changes: 21 additions & 0 deletions logic/GameClass/GameObj/Occupations/WarShip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@ public class WarShip : IOccupation
public int Cost { get; } = GameData.WarShipCost;
public int BaseArmor { get; } = GameData.WarShipBaseArmor;
public int BaseShield { get; } = GameData.WarShipBaseShield;
public bool IsModuleValid(ModuleType moduleType) => moduleType switch
{
ModuleType.Producer1 => false,
ModuleType.Producer2 => false,
ModuleType.Producer3 => false,
ModuleType.Constructor1 => false,
ModuleType.Constructor2 => false,
ModuleType.Constructor3 => false,
ModuleType.Armor1 => true,
ModuleType.Armor2 => true,
ModuleType.Armor3 => true,
ModuleType.Shield1 => true,
ModuleType.Shield2 => true,
ModuleType.Shield3 => true,
ModuleType.LaserGun => true,
ModuleType.PlasmaGun => true,
ModuleType.ShellGun => true,
ModuleType.MissileGun => true,
ModuleType.ArcGun => true,
_ => false
};
}
139 changes: 139 additions & 0 deletions logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public override bool IgnoreCollideExecutor(IGameObj targetObj)
/// 子弹数上限, THUAI7为无穷
/// </summary>
public IntNumUpdateEachCD BulletNum => new(int.MaxValue, 1);
/// <summary>
/// 模块相关
/// </summary>
#region Modules

#region Producer
private ProducerType producerType = ProducerType.Null;
public ProducerType ProducerModuleType => producerType;
Expand Down Expand Up @@ -87,6 +92,140 @@ public override bool IgnoreCollideExecutor(IGameObj targetObj)

public int ProduceSpeed => producer.ProduceSpeed;
public int ConstructSpeed => constructor.ConstructSpeed;
public bool InstallModule(ModuleType moduleType)
{
lock (actionLock)
{
if (moduleType == ModuleType.Null) return false;
if (!this.Occupation.IsModuleValid(moduleType)) return false;
switch (moduleType)
{
case ModuleType.Producer1:
if (producerType != ProducerType.Producer1)
{
producerType = ProducerType.Producer1;
producer = ModuleFactory.FindIProducer(ShipType, producerType);
return true;
}
break;
case ModuleType.Producer2:
if (producerType != ProducerType.Producer2)
{
producerType = ProducerType.Producer2;
producer = ModuleFactory.FindIProducer(ShipType, producerType);
return true;
}
break;
case ModuleType.Producer3:
if (producerType != ProducerType.Producer3)
{
producerType = ProducerType.Producer3;
producer = ModuleFactory.FindIProducer(ShipType, producerType);
return true;
}
break;
case ModuleType.Constructor1:
if (constructorType != ConstructorType.Constructor1)
{
constructorType = ConstructorType.Constructor1;
constructor = ModuleFactory.FindIConstructor(ShipType, constructorType);
return true;
}
break;
case ModuleType.Constructor2:
if (constructorType != ConstructorType.Constructor2)
{
constructorType = ConstructorType.Constructor2;
constructor = ModuleFactory.FindIConstructor(ShipType, constructorType);
return true;
}
break;
case ModuleType.Constructor3:
if (constructorType != ConstructorType.Constructor3)
{
constructorType = ConstructorType.Constructor3;
constructor = ModuleFactory.FindIConstructor(ShipType, constructorType);
return true;
}
break;
case ModuleType.Armor1:
armorType = ArmorType.Armor1;
armor = ModuleFactory.FindIArmor(ShipType, armorType);
this.Armor.SetV(armor.ArmorHP);
return true;
case ModuleType.Armor2:
armorType = ArmorType.Armor2;
armor = ModuleFactory.FindIArmor(ShipType, armorType);
this.Armor.SetV(armor.ArmorHP);
return true;
case ModuleType.Armor3:
armorType = ArmorType.Armor3;
armor = ModuleFactory.FindIArmor(ShipType, armorType);
this.Armor.SetV(armor.ArmorHP);
return true;
case ModuleType.Shield1:
shieldType = ShieldType.Shield1;
shield = ModuleFactory.FindIShield(ShipType, shieldType);
this.Shield.SetV(shield.ShieldHP);
return true;
case ModuleType.Shield2:
shieldType = ShieldType.Shield2;
shield = ModuleFactory.FindIShield(ShipType, shieldType);
this.Shield.SetV(shield.ShieldHP);
return true;
case ModuleType.Shield3:
shieldType = ShieldType.Shield3;
shield = ModuleFactory.FindIShield(ShipType, shieldType);
this.Shield.SetV(shield.ShieldHP);
return true;
case ModuleType.LaserGun:
if (weaponType != WeaponType.LaserGun)
{
weaponType = WeaponType.LaserGun;
weapon = ModuleFactory.FindIWeapon(ShipType, weaponType);
return true;
}
break;
case ModuleType.PlasmaGun:
if (weaponType != WeaponType.PlasmaGun)
{
weaponType = WeaponType.PlasmaGun;
weapon = ModuleFactory.FindIWeapon(ShipType, weaponType);
return true;
}
break;
case ModuleType.ShellGun:
if (weaponType != WeaponType.ShellGun)
{
weaponType = WeaponType.ShellGun;
weapon = ModuleFactory.FindIWeapon(ShipType, weaponType);
return true;
}
break;
case ModuleType.MissileGun:
if (weaponType != WeaponType.MissileGun)
{
weaponType = WeaponType.MissileGun;
weapon = ModuleFactory.FindIWeapon(ShipType, weaponType);
return true;
}
break;
case ModuleType.ArcGun:
if (weaponType != WeaponType.ArcGun)
{
weaponType = WeaponType.ArcGun;
weapon = ModuleFactory.FindIWeapon(ShipType, weaponType);
return true;
}
break;
default:
break;
}
return false;
}
}

#endregion

private GameObj? whatInteractingWith = null;
public GameObj? WhatInteractingWith
Expand Down
Loading

0 comments on commit 6bd8df6

Please sign in to comment.