Browse Source

完善建筑升级功能

master
star\zhenghan 3 years ago
parent
commit
ce0a5fc5df
  1. 3
      Proto/OuterMessage.proto
  2. 4
      Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs
  3. 4
      Server/Hotfix/Demo/Helper/ConstructHelper.cs
  4. 2
      Server/Hotfix/Server.Hotfix.csproj
  5. 6
      Server/Model/Generate/Message/OuterMessage.cs
  6. 2
      Unity/Animancer.FSM.csproj
  7. 2
      Unity/Animancer.csproj
  8. 4
      Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs
  9. 2
      Unity/Codes/Hotfix/Demo/Construct/ConstructSystem.cs
  10. 2
      Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs
  11. 2
      Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs
  12. 24
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  13. 5
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  14. 10
      Unity/Codes/HotfixView/Demo/Building/AfterCreateBuilding_AddComponent.cs
  15. 25
      Unity/Codes/HotfixView/Demo/FUI/Logic/Building/ConstructFinish_RefreshWindow.cs
  16. 3
      Unity/Codes/HotfixView/Demo/FUI/Logic/Building/FUIBuildingUpgradeWindowComponentSystem.cs
  17. 6
      Unity/Codes/HotfixView/Demo/FUI/Logic/Building/FUIPrepareBuildingWindowComponentSystem.cs
  18. 2
      Unity/Codes/HotfixView/Demo/People/PeopleViewComponentSystem.cs
  19. 0
      Unity/Codes/Model/Demo/Config/WorldParam.cs
  20. 10
      Unity/Codes/Model/Demo/Config/WorldParametersConfig.cs
  21. 6
      Unity/Codes/Model/Generate/Message/OuterMessage.cs

3
Proto/OuterMessage.proto

@ -67,7 +67,6 @@ message BuildingProto
int32 Durable = 5; int32 Durable = 5;
FarmlandProto Farmland = 6; FarmlandProto Farmland = 6;
int32 IsUpgrade = 7; int32 IsUpgrade = 7;
} }
message PeopleProto message PeopleProto
@ -137,6 +136,7 @@ message ConstructProto
int32 Progress = 8; int32 Progress = 8;
repeated int64 PeopleIdList = 9; repeated int64 PeopleIdList = 9;
repeated int64 PreparePeopleIdList = 10; repeated int64 PreparePeopleIdList = 10;
int64 BuildingId = 11;
} }
message SynthesisProto message SynthesisProto
@ -771,6 +771,7 @@ message M2C_NotifyUpdatePeople // IActorMessage
message M2C_NotifyConstructFinish // IActorMessage message M2C_NotifyConstructFinish // IActorMessage
{ {
int64 ConstructId = 1; int64 ConstructId = 1;
int64 BuildingId = 2;
} }
message M2C_NotifyUpdateValley // IActorMessage message M2C_NotifyUpdateValley // IActorMessage

4
Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs

@ -7,10 +7,10 @@ namespace ET
{ {
try try
{ {
ConstructOperate.ConstructFinish(unit, request.ConstructId); var building = ConstructOperate.ConstructFinish(unit, request.ConstructId);
response.Error = ErrorCode.ERR_Success; response.Error = ErrorCode.ERR_Success;
reply(); reply();
ConstructHelper.NofityConstructFinish(unit,request.ConstructId); ConstructHelper.NofityConstructFinish(unit,request.ConstructId, building.Id);
} }
catch (Exception e) catch (Exception e)
{ {

4
Server/Hotfix/Demo/Helper/ConstructHelper.cs

@ -21,9 +21,9 @@ namespace ET
} }
} }
public static void NofityConstructFinish(Unit unit, long id) public static void NofityConstructFinish(Unit unit, long id, long buildingId)
{ {
MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id}); MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id, BuildingId = buildingId});
} }
} }
} }

2
Server/Hotfix/Server.Hotfix.csproj

@ -150,7 +150,7 @@
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Unit\UnitSystem.cs"> <Compile Include="..\..\Unity\Codes\Hotfix\Demo\Unit\UnitSystem.cs">
<Link>Demo\Unit\UnitSystem.cs</Link> <Link>Demo\Unit\UnitSystem.cs</Link>
</Compile> </Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\WorldParam.cs"> <Compile Include="..\..\Unity\Codes\Model\Demo\Config\WorldParam.cs">
<Link>Demo\WorldParam.cs</Link> <Link>Demo\WorldParam.cs</Link>
</Compile> </Compile>

6
Server/Model/Generate/Message/OuterMessage.cs

@ -308,6 +308,9 @@ namespace ET
[ProtoMember(10)] [ProtoMember(10)]
public List<long> PreparePeopleIdList = new List<long>(); public List<long> PreparePeopleIdList = new List<long>();
[ProtoMember(11)]
public long BuildingId { get; set; }
} }
[Message(OuterOpcode.SynthesisProto)] [Message(OuterOpcode.SynthesisProto)]
@ -1601,6 +1604,9 @@ namespace ET
[ProtoMember(1)] [ProtoMember(1)]
public long ConstructId { get; set; } public long ConstructId { get; set; }
[ProtoMember(2)]
public long BuildingId { get; set; }
} }
[Message(OuterOpcode.M2C_NotifyUpdateValley)] [Message(OuterOpcode.M2C_NotifyUpdateValley)]

2
Unity/Animancer.FSM.csproj

@ -53,7 +53,7 @@
<UnityVersion>2021.3.7f1c1</UnityVersion> <UnityVersion>2021.3.7f1c1</UnityVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Analyzer Include="C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" /> <Analyzer Include="D:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Assets\ThirdParty\Animancer\Utilities\FSM\StateMachine1.StateSelector.cs" /> <Compile Include="Assets\ThirdParty\Animancer\Utilities\FSM\StateMachine1.StateSelector.cs" />

2
Unity/Animancer.csproj

@ -53,7 +53,7 @@
<UnityVersion>2021.3.7f1c1</UnityVersion> <UnityVersion>2021.3.7f1c1</UnityVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Analyzer Include="C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" /> <Analyzer Include="D:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Assets\ThirdParty\Animancer\Internal\Editor\Transition Preview Window\TransitionPreviewWindow.Animations.cs" /> <Compile Include="Assets\ThirdParty\Animancer\Internal\Editor\Transition Preview Window\TransitionPreviewWindow.Animations.cs" />

4
Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs

@ -57,8 +57,8 @@ namespace ET
ConstructHelper.NtfUpdateConstructProgress(unit, self); ConstructHelper.NtfUpdateConstructProgress(unit, self);
foreach (var v in finishConstructs) foreach (var v in finishConstructs)
{ {
ConstructOperate.ConstructFinish(unit, v.Id); var building = ConstructOperate.ConstructFinish(unit, v.Id);
ConstructHelper.NofityConstructFinish(unit,v.Id); ConstructHelper.NofityConstructFinish(unit,v.Id, building.Id);
} }
if (finishConstructs.Count > 0) if (finishConstructs.Count > 0)

2
Unity/Codes/Hotfix/Demo/Construct/ConstructSystem.cs

@ -15,6 +15,7 @@ namespace ET
self.ConfigId = constructProto.ConfigId; self.ConfigId = constructProto.ConfigId;
self.PeopleIdList = constructProto.PeopleIdList; self.PeopleIdList = constructProto.PeopleIdList;
self.PreparePeopleIdList = constructProto.PreparePeopleIdList; self.PreparePeopleIdList = constructProto.PreparePeopleIdList;
self.BuildingId = constructProto.BuildingId;
} }
public static ConstructProto ToMessage(this Construct self) public static ConstructProto ToMessage(this Construct self)
@ -28,6 +29,7 @@ namespace ET
proto.ConfigId = self.ConfigId; proto.ConfigId = self.ConfigId;
proto.PeopleIdList = self.PeopleIdList; proto.PeopleIdList = self.PeopleIdList;
proto.PreparePeopleIdList = self.PreparePeopleIdList; proto.PreparePeopleIdList = self.PreparePeopleIdList;
proto.BuildingId = self.BuildingId;
return proto; return proto;
} }

2
Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs

@ -5,7 +5,7 @@
{ {
protected override void Run(Session session, M2C_NotifyConstructFinish message) protected override void Run(Session session, M2C_NotifyConstructFinish message)
{ {
var building = ConstructOperate.ConstructFinish(UnitComponent.unit,message.ConstructId); var building = ConstructOperate.ConstructFinish(UnitComponent.unit,message.ConstructId, message.BuildingId);
UnitOperate.InitProsperity(UnitComponent.unit); UnitOperate.InitProsperity(UnitComponent.unit);
if (building != null) if (building != null)
{ {

2
Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs

@ -13,7 +13,7 @@ namespace ET
M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct; M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct;
if (resp.Error == ErrorCode.ERR_Success) if (resp.Error == ErrorCode.ERR_Success)
{ {
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit, configId, x, y, resp.Id); var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit, configId, x, y, resp.Id, buildingId);
Game.EventSystem.Publish(new EventType.AfterCreateConstruct() { Unit = unit, Construct = construct, IsNew = true }); Game.EventSystem.Publish(new EventType.AfterCreateConstruct() { Unit = unit, Construct = construct, IsNew = true });
} }
else else

24
Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs

@ -139,7 +139,7 @@ namespace ET
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
public static Building ConstructFinish(Unit unit, long constructId) public static Building ConstructFinish(Unit unit, long constructId, long buildingId = 0)
{ {
var construct = unit.GetComponent<ConstructComponent>().GetChild<Construct>(constructId); var construct = unit.GetComponent<ConstructComponent>().GetChild<Construct>(constructId);
Building build; Building build;
@ -150,13 +150,26 @@ namespace ET
if (construct.IsUpgrade) if (construct.IsUpgrade)
{ {
build = unit.GetOrAddComponent<BuildingComponent>().GetChild<Building>(construct.BuildingId); var buildingComp = unit.GetOrAddComponent<BuildingComponent>();
build.ConfigId = construct.Config.MixtureID; build = buildingComp.GetChild<Building>(construct.BuildingId);
if (build == null)
{
Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}");
}
build.IsUpgrade = 0; build.IsUpgrade = 0;
build.ConfigId = construct.Config.MixtureID;
} }
else else
{ {
build = unit.GetOrAddComponent<BuildingComponent>().AddChild<Building>(); if (buildingId > 0)
{
build = unit.GetOrAddComponent<BuildingComponent>().AddChildWithId<Building>(buildingId);
}
else
{
build = unit.GetOrAddComponent<BuildingComponent>().AddChild<Building>();
}
build.Position.x = construct.X; build.Position.x = construct.X;
build.Position.y = construct.Y; build.Position.y = construct.Y;
build.ConfigId = construct.Config.MixtureID; build.ConfigId = construct.Config.MixtureID;
@ -167,8 +180,7 @@ namespace ET
farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE; farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE;
} }
} }
StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId); StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId);
if (structureConfig != null) if (structureConfig != null)
{ {

5
Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs

@ -156,7 +156,10 @@ namespace ET
return; return;
} }
self.Season = self.SeasonConfig.Id; self.Season = self.SeasonConfig.Id;
UnitHelper.NofityUpdateValley(self, new List<int> { NumericType.Season }, new List<long> { self.Season }); #if SERVER
UnitHelper.NofityUpdateValley(self, new List<int> { NumericType.Season }, new List<long> { self.Season });
#endif
//如果是春天,长大一岁 //如果是春天,长大一岁
} }

10
Unity/Codes/HotfixView/Demo/Building/AfterCreateBuilding_AddComponent.cs

@ -2,14 +2,20 @@
namespace ET namespace ET
{ {
[FriendClass(typeof(Building))]
public class AfterCreateBuilding_AddComponent : AEvent<EventType.AfterCreateBuilding> public class AfterCreateBuilding_AddComponent : AEvent<EventType.AfterCreateBuilding>
{ {
protected override void Run(AfterCreateBuilding args) protected override void Run(AfterCreateBuilding args)
{ {
var unit = args.Unit; var unit = args.Unit;
var building = args.Building; var building = args.Building;
var buildingViewComp = building.AddComponent<BuildingViewComponent>(); // 升级的过程中不显示原先的建筑
buildingViewComp.CreateName().Coroutine(); if (building.IsUpgrade == 0)
{
var buildingViewComp = building.AddComponent<BuildingViewComponent>();
buildingViewComp.CreateName().Coroutine();
}
// update map info // update map info
} }
} }

25
Unity/Codes/HotfixView/Demo/FUI/Logic/Building/ConstructFinish_RefreshWindow.cs

@ -0,0 +1,25 @@
using ET.EventType;
namespace ET
{
using FUIBuilding;
public class ConstructFinish_RefreshWindow : AEvent<EventType.AfterCreateBuilding>
{
protected override void Run(AfterCreateBuilding args)
{
var unit = args.Unit;
var building = args.Building;
var win = FUIComponent.Instance.GetWindow(FUI_BuildingInfoWindow.UIResName);
if (win != null)
{
var BuildingWin = win as FUIBuildingInfoWindowComponent;
if (BuildingWin.Window.isShowing)
{
BuildingWin.ShowInfo(building);
}
}
}
}
}

3
Unity/Codes/HotfixView/Demo/FUI/Logic/Building/FUIBuildingUpgradeWindowComponentSystem.cs

@ -76,9 +76,10 @@ namespace ET
self.CurUpgradeSynthesisConfigId = synthesisConfig.Id; self.CurUpgradeSynthesisConfigId = synthesisConfig.Id;
if (synthesisConfig != null) if (synthesisConfig != null)
{ {
float discount = WorldParametersConfigCategory.Instance.GetUpgradePercent();
for (int i = 0; i < synthesisConfig.ItemId.Length; i++) for (int i = 0; i < synthesisConfig.ItemId.Length; i++)
{ {
self.SetMaterialData(self.MaterialButtons[i], synthesisConfig.ItemId[i], synthesisConfig.ItemNum[i]); self.SetMaterialData(self.MaterialButtons[i], synthesisConfig.ItemId[i], (int)(synthesisConfig.ItemNum[i] * discount));
} }
for (int j = synthesisConfig.ItemId.Length; j < 4; j++) for (int j = synthesisConfig.ItemId.Length; j < 4; j++)

6
Unity/Codes/HotfixView/Demo/FUI/Logic/Building/FUIPrepareBuildingWindowComponentSystem.cs

@ -58,7 +58,7 @@ namespace ET
// init event // init event
self.FUIPrepareBuildingWindow.m_AddSpeedButton.FGComp.onClick.Add(self.OnAddSpeedButtonClick); self.FUIPrepareBuildingWindow.m_AddSpeedButton.FGComp.onClick.Add(self.OnAddSpeedButtonClick);
self.FUIPrepareBuildingWindow.m_CompleteButton.FGComp.onClick.Add(self.OnCompleteButtonClick); self.FUIPrepareBuildingWindow.m_CompleteButton.FGComp.AddClickListenerAsync(self.OnCompleteButtonClick);
self.FUIPrepareBuildingWindow.m_CancelBuildingButton.FGComp.AddClickListenerAsync(self.OnCancelBuildingButtonClick); self.FUIPrepareBuildingWindow.m_CancelBuildingButton.FGComp.AddClickListenerAsync(self.OnCancelBuildingButtonClick);
} }
@ -153,8 +153,10 @@ namespace ET
Log.Debug("AddSpeed Button Click"); Log.Debug("AddSpeed Button Click");
} }
public static void OnCompleteButtonClick(this FUIPrepareBuildingWindowComponent self) public static async ETTask OnCompleteButtonClick(this FUIPrepareBuildingWindowComponent self)
{ {
Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene());
await ConstructHelper.ConstructFinish(unit, self.Construct.Id);
Log.Debug("Complete Button Click"); Log.Debug("Complete Button Click");
} }

2
Unity/Codes/HotfixView/Demo/People/PeopleViewComponentSystem.cs

@ -132,7 +132,7 @@ namespace ET
{ {
if (!self.Agent.hasPath || self.Agent.velocity.sqrMagnitude == 0f) if (!self.Agent.hasPath || self.Agent.velocity.sqrMagnitude == 0f)
{ {
Log.Info("Reach Dest"); // Log.Info("Reach Dest");
self.Stop(); self.Stop();
} }
} }

0
Unity/Codes/Hotfix/Demo/WorldParam.cs → Unity/Codes/Model/Demo/Config/WorldParam.cs

10
Unity/Codes/Model/Demo/Config/WorldParametersConfig.cs

@ -0,0 +1,10 @@
namespace ET
{
public partial class WorldParametersConfigCategory
{
public float GetUpgradePercent()
{
return Get(WorldParam.UpgratePercent).Value[0] / 100.0f;
}
}
}

6
Unity/Codes/Model/Generate/Message/OuterMessage.cs

@ -308,6 +308,9 @@ namespace ET
[ProtoMember(10)] [ProtoMember(10)]
public List<long> PreparePeopleIdList = new List<long>(); public List<long> PreparePeopleIdList = new List<long>();
[ProtoMember(11)]
public long BuildingId { get; set; }
} }
[Message(OuterOpcode.SynthesisProto)] [Message(OuterOpcode.SynthesisProto)]
@ -1601,6 +1604,9 @@ namespace ET
[ProtoMember(1)] [ProtoMember(1)]
public long ConstructId { get; set; } public long ConstructId { get; set; }
[ProtoMember(2)]
public long BuildingId { get; set; }
} }
[Message(OuterOpcode.M2C_NotifyUpdateValley)] [Message(OuterOpcode.M2C_NotifyUpdateValley)]

Loading…
Cancel
Save